SHIFT statement

Purpose

Shift the bits in an integral-class variable.

Syntax

SHIFT [SIGNED] {LEFT | RIGHT} ivar, countexpr

Remarks

ivar must be one of the integral-class variable types: Byte, Word, Integer, Double-word, Long-integer, or Quad-integercountexpr is an integral-class expression specifying the number of bits by which to shift ivar.

SHIFT shifts all the bits in ivar without special regard to the sign bit of a signed integral-class variable.

SIGNED

The SIGNED option shifts everything, but does not allow the sign (positive or negative) of the value to change.

LEFT | RIGHT

The LEFT or RIGHT option determines the direction of the bit SHIFT operation.  SHIFT LEFT shifts the bits toward the high-order end of ivar, and SHIFT RIGHT shifts bits toward the low-order end of ivar.

See also

AND, BIT functionBIT statement, BITS functions, NOT, OR, ROTATE, XOR

Example

DIM i AS BYTE

n = 221

SHIFT LEFT n, 1          ' binary 1 1 0 1 1 1 0 1

' n = 186                ' binary 1 0 1 1 1 0 1 0

 

n = 221

SHIFT RIGHT n, 1         ' binary 1 1 0 1 1 1 0 1

' n = 110                ' binary 0 1 1 0 1 1 1 0

 

n = 221

SHIFT SIGNED RIGHT n, 1  ' binary 1 1 0 1 1 1 0 1

n = 238                  ' binary 1 1 1 0 1 1 1 0