Bitwise Shift Right '>>', '>>='

The Bitwise Shift Right operator shifts the bits of the first operand right by the number of bits indicated in the second operand. The original LSBs (rightmost bits) drop off and the new MSBs (leftmost bits) are set to zero. Bitwise Shift Right can be used in both variable and integer constant expressions, but not in floating-point constant expressions. Example:

X := Y >> 3

If Y started out as:

%10000000 01110000 11111111 00110101

...the Bitwise Shift Right operator would shift that value right by three bits, setting X to:

%00010000 00001110 00011111 11100110

Since the nature of binary is base-2, shifting a value right is like performing an integer divide of that value by powers of two, 2b, where b is the number of bits shifted.

Bitwise Shift Right has an assignment form, >>=, that uses the variable to its left as both the first operand and the result destination. For example,

X >>= 2     'Short form of X := X >> 2

Here, the value of X is shifted right two bits and is stored back in X. The assignment form of Bitwise Shift Right may also be used within expressions for intermediate results; see Intermediate Assignments.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.