Core Function BinaryLen

From Sputnik Wiki
Revision as of 12:38, 14 June 2015 by UberFoX (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
BinaryLen( <binary-array>, <newLen>, <fillWith> )

Contents

Description

Returns the number of bytes in a binary variable.

Or increase it's capacity for bytes by using the second parameter.

Parameters

binary-array

The binary variable to check its size.

newLen

Optional; If provided the Binary variable data array will be expanded to this new size.

Note - new lengths below the size of the current length are totally ignored and do nothing.

fillWith

Optional; The byte to fill in new bytes with if using the newLen

Default: 0x00

Return Value

If using only one parameter

Success: Returns the length of the binary data in bytes.

Failure: Returns -1.

If using the newLen parameter

Success: Returns true.

Failure: Returns -1.

Remarks

UBound works just as good for this if you only wish to see its current size.

Example

$binary = BinaryHex("48656c6c6f20576f726c6421");
println( "Binary HEX: '" . BinaryStr($binary, ",") . "'" );
println("The binary size is: " . BinaryLen($binary) );
Foreach ($binary as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("A*", $binary, 3);
println("Full string: " . $String);

Example of setting the length

// Make a binary of "Hello"
my $a = Pack("A*", "Hello");
// Print it
say BinaryExpand($a);
// Expand its size
BinaryLen($a, 11);
// Write more data
$a[5] = @' ';
$a[6] = @'w';
$a[7] = @'o';
$a[8] = @'r';
$a[9] = @'l';
$a[10] = @'d';
// Print it
say BinaryExpand($a);
// Prints:
// 48 65 6C 6C 6F -- -- -- -- -- -- -- -- -- -- -- Hello
// 48 65 6C 6C 6F 20 77 6F 72 6C 64 -- -- -- -- -- Hello world

Example of setting the length and fill with

// Make a binary of "Hello"
my $a = Pack("A*", "Hello");
// Print it
say BinaryExpand($a);
// Expand its size
BinaryLen($a, 100, 0x4A);
// Print it
say BinaryExpand($a);
// Prints:
// 48 65 6C 6C 6F -- -- -- -- -- -- -- -- -- -- -- Hello
// 48 65 6C 6C 6F 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A HelloJJJJJJJJJJJ
// 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A JJJJJJJJJJJJJJJJ
// 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A JJJJJJJJJJJJJJJJ
// 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A JJJJJJJJJJJJJJJJ
// 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A JJJJJJJJJJJJJJJJ
// 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A 4A JJJJJJJJJJJJJJJJ
// 4A 4A 4A 4A -- -- -- -- -- -- -- -- -- -- -- -- JJJJ
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox