"Sputnik" help  
Sputnik Help
BitSwap(<value>)

Description

Swaps the bytes of a given value.

Parameters

<value> The value to swap the bytes.

Return Value

Success: Returns the value with the bytes swapped.
Failure: Returns 0.

Remarks

The BitSwap function reverses the order of the bytes within the given value. It performs the byte swap operation based on the size of the value.

When a string is provided as the input value, the BitSwap function converts the string to a numeric value and performs the byte swap operation accordingly. The conversion process recognizes different numeric formats and selects the appropriate data type (e.g., Double, Int64, Int32) based on the string content.

The BitSwap function is useful for manipulating data at the byte level, such as when dealing with endianess or byte order.

Related

Example

Example of usage:

my $a = (UInt16)0b0000000011110000;
my $b = (UInt16)0b0000000000110011;
my $c = (UInt16)0b0000000000001100;
my $d = (UInt16)0b0000000000000011;
say "Normal";
say unpack("B*", $a, @UnpackSingle);
say unpack("B*", $b, @UnpackSingle);
say unpack("B*", $c, @UnpackSingle);
say unpack("B*", $d, @UnpackSingle);
say "Swapped";
say unpack("B*", BitSwap($a), @UnpackSingle);
say unpack("B*", BitSwap($b), @UnpackSingle);
say unpack("B*", BitSwap($c), @UnpackSingle);
say unpack("B*", BitSwap($d), @UnpackSingle);

// PRINTS
// Normal
// 1111000000000000
// 0011001100000000
// 0000110000000000
// 0000001100000000
// Swapped
// 0000000011110000
// 0000000000110011
// 0000000000001100
// 0000000000000011

 


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