Shift left (SHL), shift right (SHR)
- Last UpdatedAug 14, 2024
- 1 minute read
SHL and SHR are binary operators that use only integer operands. The binary content of the 32-bit word referenced by the quantity to the left of the operator is shifted (right or left) by the number of bit positions specified in the quantity to the right of the operator.
Bits shifted out of the word are lost. Bit positions vacated by the shift are zero-filled. The shift is an unsigned shift.
Example 1
If Attribute2 = 00000111 (decimal 7)
Then the operation:
Attribute1 = Attribute2 SHL 3;
Results in:
Attribute1 = 00111000 (decimal 56)
Example 2
If Attribute2 = 00001011 (decimal 11)
Then the operation:
Attribute1 = Attribute2 SHR 2;
Results in:
Attribute1 = 00000010 (decimal 2)