Core Function BinaryReverse

From Sputnik Wiki
Jump to: navigation, search
BinaryReverse( <binary-array>, <start>, <length> ) 

Contents

Description

Reverse the order bytes a binary variable.

Parameters

binary-array

The binary variable to use.

start

Optional; Position to start from.

Default is 0;

length

Optional; How many bytes to reverse.

Default is all remaining bytes;

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

This modifies the original binary data.

Example

$binary = Pack("A*", "Hello World!");
BinaryReverse($binary);
println( "Binary HEX: '" . BinaryStr($binary, ",") . "'" );
println("The binary size is: " . UBound($binary) );
Foreach ($binary as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("A*", $binary, 3);
println("Full string: " . $String);

Reverse everything after "He" example:

$binary = Pack("A*", "Hello World!");
BinaryReverse($binary, 2);
println( "Binary HEX: '" . BinaryStr($binary, ",") . "'" );
println("The binary size is: " . UBound($binary) );
Foreach ($binary as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("A*", $binary, 3);
println("Full string: " . $String);

Reverse the "World" part example:

$binary = Pack("A*", "Hello World!");
BinaryReverse($binary, 6, 5);
println( "Binary HEX: '" . BinaryStr($binary, ",") . "'" );
println("The binary size is: " . UBound($binary) );
Foreach ($binary as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("A*", $binary, 3);
println("Full string: " . $String);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox