Quiz Entry - updated: 2026.07.07
What is the difference between logical and arithmetic right shift?
Both shift right; a logical shift fills the new high bits with 0, while an arithmetic shift fills them with copies of the sign bit so a negative value stays negative.
* Right-shifting a negative value by 2: the logical shift pulls in 0s (unsigned), while the arithmetic shift replicates the sign bit 1 so the value stays negative. *
For x = 10100010 shifted right by 2:
Logical: 00101000 (filled with 0s)
Arithmetic: 11101000 (filled with 1s, the sign bit)
When each is used:
- Logical: Unsigned integers, extracting bit fields
- Arithmetic: Signed integers (preserves sign, equivalent to division)
Warning in C: >> behavior for signed integers is implementation-defined! Most compilers use arithmetic shift for signed types.
Go deeper:
Arithmetic shift (Wikipedia) — how it differs from a logical shift and why it divides signed values.