BitShift

From AutoIt Wiki

Jump to: navigation, search

Performs a bit shifting operation. Adapted from AutoIt docs.

Contents

[edit] Syntax

$x = BitShift(value,shift)

[edit] Parameters

valueThe number to be shifted.
shiftNumber of bits to shift to the right (negative numbers shift left).

[edit] Return Value

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

As a standard, shifting bits is equivalent to multiplying/dividing by an order of magnitude. That is to say, a binary number shifted n bits is equivalent to multiplying by 2^n.

[edit] Example

$x = BitShift(14, 2)
;  x == 3 because 1110b right-shifted twice is 11b == 3

$y = BitShift(14, -2)
;  y == 56 because 1110b left-shifted twice is 111000b == 56

$z = BitShift( 1, -31)
;  z == -2147483648 because in 2's-complement notation, the
;  32nd digit from the right has a negative sign.

[edit] Related Functions

BitAND BitNOT BitOR BitXOR BitRotate Hex

Personal tools