Core Function BitROTATE

From Sputnik Wiki
Jump to: navigation, search
BitROTATE( <expression>, <shift>, <size> )

Contents

Description

Performs a bit shifting operation, with rotation.

Parameters

expression

Any valid numeric expression.

shift

Optional; Number of bits to rotate to the left (negative numbers rotate right). If not given, the default is 1.

shift

Optional; A string that determines the rotation size, the default is (16 bits). See below.

"B"	rotate bits within the low-order byte (8 bits).
"W"	rotate bits within the low-order word (16 bits).
"D"	rotate bits within the entire double-word (32 bits).

Return Value

Success: Returns the value rotated by the required number of bits.

Failure: Returns 0.

Example

my $x = BitRotate(7, 2);
my $y = BitRotate(14, -2);
my $z = BitRotate(14, -2, "D");
 
//  x == 28 because 111b left-rotated twice is 1 1100b == 28
println( "X:" . $x );
 
//  y == 32771 because 1110b right-rotated twice on 16 bits is 1000 0000 0000 0011b == 32771
println( "Y:" . $y );
 
//  z == -2147483645 because 1110b right-rotated twice on 16 bits is 1000 0000 0000 0000 0000 0000 0000 0011b == 2147483645
println( "Z:" . $z );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox