You are here: Function Reference > Alphabetical Listing > B > BitShift

BitShift

Use this function to return the result of a bit logical shift operation performed on a numeric value.

Syntax

BitShift(Value1, ShiftAmt)

The first parameter specifies the numeric value on which the bitwise shift operation is performed. The second parameter specifies the number of bit positions to shift. If either parameter is not an integer, it will be converted to an integer before the bitwise shift operation is performed.

This is a logical shift, as opposed to a shift-and-rotate operation. This means bits shifted off the end of a value are considered lost.

Note See the BitRotate function for shift-and-rotate.

A positive shiftAmt value causes the bit pattern in value1 to be shifted left the number of bits specified by ShiftAmt. Bits vacated by the shift operation are zero-filled.

A negative shiftAmt value causes the bit pattern in value1 to be shifted right the number of bits specified by ShiftAmt. Bits vacated by the shift operation are zero-filled.

Note that integer values have 32 bits. Attempting to shift more than 31 bit positions will result in a zero (0) being returned, as all bits are cleared.

The following table shows the result of a bitwise SHIFT operation:

 

Shift

Result value bits

6 (0110)

1

12 (1100)

6 (0110)

2

24 (0001 1000)

6 (0110)

3

48 (0011 0000)

6 (0110)

4

 

6 (0110)

-1

3 (0011)

6 (0110)

-2

1 (0001)

6 (0110)

-3

0 (0000)

6 (0110)

-4

0 (0000)

Example

Here is an example:

z = BitShift(6,8)

z = 1536 (1536 is 0110 0000 0000 in binary)

See also