Core Function BinaryHex

From Sputnik Wiki
Revision as of 14:02, 9 August 2013 by UberFoX (Talk | contribs)
Jump to: navigation, search
BinaryHex( <expression>, <flag> )

Contents

Description

Create a binary array from a hex string.

Parameters

expression

A string of hex to convert into a binary variable.

flag

Optional; True if the string actually is hex using \x escape or False if the string is just hex digits in text

Return Value

Success: Returns the binary variable.

Failure: Returns 0.

Remarks

The string must contain only the hex chars nothing else not even 0x or spaces.

Example

$binary = BinaryHex("48656c6c6f20576f726c6421");
println( "Binary HEX: '" . BinaryStr($binary, ",") . "'" );
println("The binary size is: " . BinaryLen($binary) );
Foreach ($binary as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("z0", $binary);
println("Full string: " . $String);

Example of using the flag

$binary = BinaryHex("\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21", true);
println( "Binary HEX: '" . BinaryStr($binary, ",") . "'" );
println("The binary size is: " . BinaryLen($binary) );
Foreach ($binary as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("z0", $binary);
println("Full string: " . $String);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox