BitRotate

From AutoIt Wiki

Jump to: navigation, search

Performs a bit shifting operation with rotation. Adapted from AutoIt docs.

Contents

Syntax

$x = BitRotate(value, shift [, size])

Parameters

valueThe number to shift.
shiftNumber of bits to rotate. Default 1.
sizeA string that determines the rotation size.(Optional)

Shift

Shift will rotate to the right if negative and left if positive.

Size

Defaults to 16 bits. Otherwise the size parameter may be set to the following:

Brotate bits within the low-order byte (8 bits)
Wrotate bits within the low-order word (16 bits)
Drotate bits within the double word (32 bits)

Return Value

Returns the value rotated by the required number of bits. Bit operations are performed as 32-bit integers.

Example

$x = BitRotate(7, 2)
;  x == 3 because 111b left-rotated twice is 1 1100b == 28

$y = BitRotate(14, -2)
;  y == 32771 because 1110b right-rotated twice on 16 bits is 1000 0000 0000 0011b == 32771

$z = BitRotate(14, -2, "D")
;  z == -2147483645 because 1110b right-rotated twice on 16 bits is 1000 0000 0000 0000 0000 0000 0000 0011b == 2147483645

Related Functions

BitShift BitAND BitNOT BitOR BitXOR Hex

Personal tools