Core Function BitSwap
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> BitROTATE( <expression> ) </pre> === Description === Byte-swap of the expression (little-endian <-> big-endian) === Parameters === ==== expression ==== Any valid numer...") |
|||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | + | BitSwap( <expression> ) | |
</pre> | </pre> | ||
Revision as of 18:12, 8 August 2014
BitSwap( <expression> )
Contents |
Description
Byte-swap of the expression (little-endian <-> big-endian)
Parameters
expression
Any valid numeric expression.
Return Value
Success: Returns the value with its bytes swapped to convert to/from endians.
Failure: Returns NULL.
Remarks
This function is smart enough to see what type of variable you are using such as Int16, UInt16, Float, Double etc etc and byte swap accordingly you will get back the same you gave it.
So if you swap the bytes of an Int32 you will get an Int32 in the return value.
Example
A 64-Bit Integer
$a = (Int64)21216547458451; say $a; printr Pack('q', $a); $b = BitSwap($a); say $b; printr Pack('q', $b); $c = BitSwap($b); say $c;
A 64-bit Floating point
$a = (double)5684343474375685; say $a; printr Pack('d', $a); $b = BitSwap($a); say $b; printr Pack('d', $b); $c = BitSwap($b); say $c;