Core Function BinaryExpand

From Sputnik Wiki
Jump to: navigation, search
BinaryExpand( <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 printing the bytes at

If the start is a negative value the position will work backwards from the length of the binary.

length

Optional; How many bytes to print

Default is all remaining bytes;

If length is given and is negative, then that many bytes will be omitted from the end of binary (after the start position has been calculated when a start is negative).

If start denotes the position of this truncation or beyond, empty binary variable will be returned.

Return Value

Success: Returns string of the expanded binary.

Failure: Returns empty string.

Remarks

This converts a binary variable into a string of numbers followed by text so it is easy to read and understand.

This is especially good when making a Client/Server program and you wish to see what information you are getting or sending.

Example

// Create a large binary that contains some text
$bin = Pack("z0iNnz0Nz0", "Hello World!", 100, 200, 700, "Cat", 1337, "Hello world!!!");
// Print it out
say BinaryExpand($bin);
// Prints
// 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 64 00 00 00 Hello World!d...
// 00 00 00 C8 02 BC 43 61 74 00 00 05 39 48 65 6C ...È..Cat...9Hel
// 6C 6F 20 77 6F 72 6C 64 21 21 21 -- -- -- -- -- lo world!!!
//
// See how it makes it easier to see whats inside the binary?

Example of printing everything after the 4th byte

$bin = Pack("iz0iNnz0Nz0", 777, "Hello World!", 100, 200, 700, "Cat", 1337, "Hello world!!!");
say BinaryExpand($bin, 4);
// Prints
// 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 64 00 00 00 Hello World!d...
// 00 00 00 C8 02 BC 43 61 74 00 00 05 39 48 65 6C ...È..Cat...9Hel
// 6C 6F 20 77 6F 72 6C -- -- -- -- -- -- -- -- -- lo worl

Example of printing 12 bytes after the 4th byte

$bin = Pack("iz0iNnz0Nz0", 777, "Hello World!", 100, 200, 700, "Cat", 1337, "Hello world!!!");
say BinaryExpand($bin, 4, 12);
// Prints
// 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World!
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox