Core Function BinaryPadRight

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> BinaryPadRight( <binary-array>, <padSize>, <padWith>, <flag> ) </pre> === Description === Right pad a binary variable with a number of bytes or pad it to a total number o...")
 
Line 23: Line 23:
 
Default: 0x20 (Space)
 
Default: 0x20 (Space)
  
==== flag====
+
==== flag ====
  
 
Optional; Decide how to pad
 
Optional; Decide how to pad

Revision as of 22:12, 1 August 2014

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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox