"Sputnik" help  
Sputnik Help
BitRotate(<value>, [<shift>], [<size>])

Description

Performs a bitwise rotation operation on the given value and returns the result.

Parameters

<value> The value to perform the bitwise rotation on.
<shift> Optional number of bits to rotate. Negative values indicate right rotation. Default value is 1.
<size> Optional size of the value in bits. Default value is 'w'.

Return Value

Success: Returns the result of the bitwise rotation operation.
Failure: Returns same as success.

Remarks

The BitRotate function performs a bitwise rotation operation on the given value. It rotates the bits of the value by a specified number of positions. The rotation can be performed in either the left or right direction.

By default, the function performs a left rotation by 1 bit. You can specify a different number of bits to rotate by providing the <shift> parameter. A positive <shift> value indicates left rotation, while a negative <shift> value indicates right rotation.

Additionally, you can specify the size of the value in bits using the <size> parameter. The available options for <size> are:

The rotation is performed within the specified size limit. If the <shift> parameter is positive, the rotation is in the left direction. If the <shift> parameter is negative, the rotation is in the right direction.

Additionally, you can specify the size of the value in bits using the <size> parameter. The rotation is performed within the specified size limit, which means that any bits outside the specified size are discarded. This is particularly useful when you want to perform the rotation within a specific range of bits.

Related

Example

Example of usage:

my $x = BitRotate(7, 2);
my $y = BitRotate(14, -2);
my $z = BitRotate(14, -2, 'D');
my $v = BitRotate(14, -2, 'Q');
 
//  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 );
 
// $v == -9223372036854775805 because 1110b
// right-rotated twice on 64 bits is 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0011b == 9223372036854775805
println( "V:" . $v );

// PRINTS
// X:28
// Y:32771
// Z:-2147483651
// V:-9223372036854775805

 


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