Skip to content

Bit Shift

Bit shift operators move or shift digits to the left or right, and can be used in arithmetic expressions. There are four variants:

  • Right Bit Shift, '>>'
  • Left Bit Shift, '<<'
  • Cyclic Right Bit Shift, 'CRShift'
  • Cyclic Left Bit Shift, 'CLShift'

The left argument is the register and the right argument is the number of bits to shift for all variants.

Right Bit Shift

The right bit shift operator shifts bits to the right: the LSBs are discarded and the other bits are 'pushed' to the right. In the case of a signed register leftmost bits are filled with the original MSB value. In the case of an unsigned register the leftmost bits are filled with '0'.

The radix point location remains fixed.

Unsigned: \(10010111\) (decimal 151) \(>> 2 = 00100101\) (decimal 37)

Signed: \(10010111\) (decimal -105) \(>> 2 = 11100101\) (decimal -27)

Left Bit Shift

The left bit shift operator shifts bit to the left and add zeros from the right. The radix point location remains fixed.

\(1.01\) (decimal 1.25) \(<< 2 = 101.00\) (decimal 5)

Cyclic Bit Shift

Moves the bits in a cyclic manner keeping the string size fixed.

\(CRShift(10100,2) = 00101\)

\(CLShift(10100,2) = 10010\)