Search⌘ K
AI Features

Arithmetic and Logical Right Shifts

Explore how arithmetic and logical right shifts operate on binary numbers to efficiently divide by powers of two. Understand the difference between preserving signs with arithmetic shifts and making numbers positive with logical shifts, including practical examples and formulas.

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} = 6.

The binary representation of the number 6 is as ...