Core Function BinaryResize
From Sputnik Wiki
BinaryResize( <binary-array>, <size>, <data> )
Contents |
Description
Resize a binary variables data array.
Parameters
binary-array
The binary variable to use.
size
The new size for the binary variables data array.
data
Optional; The byte to place into all new slots (Assuming the new array is larger than the old).
Default is 0
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
This modifies the original binary variable and does not return a copy.
Example
Resize a binary to contain just 1 word:
$binary = Pack("A*", "Hello World!"); BinaryResize($binary, 5); $k = 0; Foreach ($binary as $i) { println( "($k) Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); $k++; } println( Unpack("A*", $binary, 3) ); // Prints: Hello
Resize a binary and fill in the gaps with ! symbols :
$binary = Pack("A*", "Hello World!"); BinaryResize($binary, 20, Asc("!")); $k = 0; Foreach ($binary as $i) { println( "($k) Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); $k++; } println( Unpack("A*", $binary, 3) ); // Prints: Hello World!!!!!!!!!