Core Function BitSwap

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
 
(2 intermediate revisions by one user not shown)
Line 24: Line 24:
  
 
So if you swap the bytes of an Int32 you will get an Int32 in the return value.
 
So if you swap the bytes of an Int32 you will get an Int32 in the return value.
 +
 +
Also this function if given a byte/sbyte will return it unchanged but String, bool and objects etc will cause a NULL return value.
  
 
=== Example ===
 
=== Example ===

Latest revision as of 12:37, 14 June 2015

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.

Also this function if given a byte/sbyte will return it unchanged but String, bool and objects etc will cause a NULL 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;
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox