...

/

Arithmetic and Logical Right Shifts

Arithmetic and Logical Right Shifts

The logical right shift means shifting the bits to the right, and MSB(most significant bit) becomes 0. The arithmetic right shift means shifting the bits to the right, and MSB is the same as in the original number.

Logical right shift (>>>)

The logical right shift operator is written as >>>.

Integers are stored in memory as a series of bits. For example, the number 12 stored as a 32-bit int would be:

12 = 00000000 00000000 00000000 00001100

When we shift it one position (12 >>> 1), the answer is 6.

12 >>> 1 = 1221\frac{12}{2^1} = 122\frac{12}{2} ...

Access this course and 1400+ top-rated courses and projects.