Core Function BinaryPadRight
From Sputnik Wiki
BinaryPadRight( <binary-array>, <padSize>, <padWith>, <flag> )
Contents |
Description
Right pad a binary variable with a number of bytes or pad it to a total number of bytes.
Parameters
binary-array
The binary variable to use.
padSize
The size of the padding.
padWith
Optional; A byte to pad with.
Default: 0x20 (Space)
flag
Optional; Decide how to pad
True = Will pad the binary until it reaches the given padSize in total size False = Will add the padWith the padSize number of times
Default: false
Return Value
Success: Returns true.
Failure: Returns false (Also returns false on flag TRUE if you try pad below the size of the binary).
Remarks
None.
Example
Pad 3 bytes only
// Create the binary $a = Pack("A*", "Hello"); // Print it say "Before:"; say BinaryExpand($a); // Pad it BinaryPadRight($a, 3, 0x20); // Print result say "After:"; say BinaryExpand($a); // Prints: // Before: // 00 | 48 65 6C 6C 6F -- -- -- -- -- -- -- -- -- -- -- Hello // After: // 00 | 48 65 6C 6C 6F 20 20 20 -- -- -- -- -- -- -- -- Hello
Force the binary to become a certain size and use padding to get there (Returns false if it does not get to the size you wanted)
// Create the binary $a = Pack("A*", "Hello"); // Print it say "Before:"; say BinaryExpand($a); // Pad it BinaryPadRight($a, 12, 0x20, true); // Print result say "After:"; say BinaryExpand($a); // Prints: // Before: // 00 | 48 65 6C 6C 6F -- -- -- -- -- -- -- -- -- -- -- Hello // After: // 00 | 48 65 6C 6C 6F 20 20 20 20 20 20 20 -- -- -- -- Hello