Binary Shifts
An arithmetic shift moves a binary pattern left or right. It is the shift you use for signed integers, such as two's complement numbers, because a right shift keeps the sign of the number the same. The bit that carries the sign is the leftmost bit, the most significant bit (MSB).
An arithmetic right shift moves every bit one place to the right and copies the sign bit into each vacant position on the left. Because the sign bit is copied rather than replaced, the sign is preserved: a negative number stays negative and a positive number stays positive.
Each place shifted right halves the value, so n places divide it by 2^n, discarding any remainder. For example, take −46 as the 8-bit pattern 1101 0010. Shifting right one place copies the 1 from the MSB into the gap, giving 1110 1001, which is −23 — exactly half of −46, still negative.
An arithmetic left shift moves every bit to the left and fills the vacant positions on the right with zeros. This makes it identical to a logical left shift, because a logical left shift also fills with zeros; there is nothing to preserve at the right-hand end.
Each place shifted left doubles the value, so n places multiply it by 2^n. For instance, 1101 0010 (−46) shifted left one place becomes 1010 0100, which is −92.
| Right shift | Bits filling the left | Sign after shifting | Correct for a signed integer? |
|---|---|---|---|
| Logical | 0 | Set to 0 | No |
| Arithmetic | A copy of the sign bit | Kept | Yes |
A logical right shift on a negative two's complement number forces the sign bit to 0, so the answer is wrong for a signed integer: 1101 0010 (−46) shifted logically right one place gives 0110 1001, which is 105. The only difference between the two right shifts is that single fill bit.
Edexcel GCSE Computer Science · Binary Shifts