"Sputnik" help  
Sputnik Help
Bt64(<binary/number>)

Description

Converts a binary string or a numeric value to its corresponding text representation. This function supports two use cases:

Binary to Integer Conversion: If provided with a binary string, Bt64 interprets the eight four bytes as a network byte order 64-bit integer and converts it to an integer value.

Integer to Text Conversion: If provided with a numeric value, Bt64 skips the binary to integer conversion step and directly converts the numeric value to its text representation.

Parameters

<binary/number> The binary string or numeric value to convert.

Return Value

Success: Returns the text representation of the binary string or numeric value.
Failure: Returns an empty string.

Remarks

When converting a binary string to an integer, the binary is assumed to be in network byte order, with the first eight bytes representing the integer value.
When converting a numeric value to text, Bt directly returns the text representation of the numeric value without any additional steps.

Related

Tb64

Example

Example of usage:

// using as numeric
my $a = Tb16("P.");
my $b = Tb("PNG.");
my $c = Tb64("CSS-HTML");

say $a;
say $b;
say $c;

say Bt16($a);
say Bt($b);
say Bt64($c);

// using as binary
my $bin = Pack("sik", $a, $b, $c);
say BinaryExpand($bin, false);
my list ($aa, $bb, $cc) = Unpack("s/i/k", $bin);

say Bt16($aa);
say Bt($bb);
say Bt64($cc);
// PRINTS
// 20526
// 1347307310
// 4851312677560274252
// P.
// PNG.
// CSS-HTML
// 2E 50 2E 47 4E 50 43 53 53 2D 48 54 4D 4C -- -- .P.GNPCSS-HTML
// P.
// PNG.
// CSS-HTML

Check a magic number:

// pack the data
my $data = Pack("Nz0", Tb("PNG."), "Hello World!");
// print it
say BinaryExpand($bin, false);

// extract magic number
my $magicNumber = $data[:4];

// check magic number
if (Bt($magicNumber) == "PNG.")
{
    say "Magic number was correct!";
    say "Data is: " . UnpackSingle("z0", $data, 4);
}
else
    say "Magic number was incorrect!";

// PRINTS
// Magic number was correct!
// Data is: Hello World!

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org