Math Fundamentals18 sections · 814 units
Open in Course

Right Shift (>>)

Divide by powers of 2

The right shift operator (>>) moves all bits to the right by a specified number of positions. Bits that fall off the right edge are discarded.

Example: 20>>220 >> 2. In binary, 20=1010020 = 10100. Shifting right by 2 positions gives 101=5101 = 5. Shifting right by kk positions divides the number by 2k2^k (using integer division). Here, 20/22=520 / 2^2 = 5.

For positive numbers, new bits on the left are filled with 0. For negative numbers, the behavior depends on the language (arithmetic shift vs logical shift), but you'll typically work with positive numbers in bit manipulation problems.