The diagram shows an 8-bit register holding a positive integer. Two separate shifts are performed on this original value: a logical left shift of three places, and a logical right shift of three places.
Give the 8-bit result of each shift, and explain which result is a correct multiplication or division of the original value.
Model answer
Left shift of 3 places: 01000000
Right shift of 3 places: 00000101
The original is 40. The right shift gives 5, which is exactly 40 ÷ 8, because the three bits lost on the right were all 0. The left shift should give 40 × 8 = 320, but this is greater than 255; the bits shifted out on the left were 001, so a 1 was lost and the register holds 64, which is wrong.
Explanation
Look at which bits fall off each end. Right: 000 is lost, so the division is exact. Left: 001 is lost, so part of the answer (256) disappears and 320 − 256 = 64 is left.