Core Function BinaryResize
From Sputnik Wiki
(Difference between revisions)
(→Example) |
|||
Line 38: | Line 38: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $binary = Pack(" | + | $binary = Pack("A*", "Hello World!"); |
BinaryResize($binary, 5); | BinaryResize($binary, 5); | ||
$k = 0; | $k = 0; | ||
Line 46: | Line 46: | ||
$k++; | $k++; | ||
} | } | ||
− | println( Unpack(" | + | println( Unpack("A*", $binary, 3) ); // Prints: Hello |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 52: | Line 52: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $binary = Pack(" | + | $binary = Pack("A*", "Hello World!"); |
BinaryResize($binary, 20, Asc("!")); | BinaryResize($binary, 20, Asc("!")); | ||
$k = 0; | $k = 0; | ||
Line 60: | Line 60: | ||
$k++; | $k++; | ||
} | } | ||
− | println( Unpack(" | + | println( Unpack("A*", $binary, 3) ); // Prints: Hello World!!!!!!!!! |
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 16:37, 27 September 2013
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!!!!!!!!!