How Binary Shifts Multiply and Divide by Powers of 2
Learn why left binary shifts multiply by powers of 2 and right shifts divide, with an 8-bit example showing discarded remainders and overflow in GCSE Computer Science.
A left binary shift by nnn places multiplies an unsigned binary number by 2n2^n2n, provided the result fits in the available bits. A right binary shift by nnn places divides it by 2n2^n2n, discarding any remainder. This works because each place in a binary number is worth twice as much as the place to its right.
Why shifts work
The place values in binary, reading from right to left, are 1,2,4,81, 2, 4, 81,2,4,8, and so on. Moving a bit one place left doubles its value; moving it one place right halves its value. Shifting two places has the same effect twice, so it multiplies or divides by 22=42^2=422=4. The number of shift places tells you which power of 222 to use.
Worked example
Assume we are using an unsigned 888-bit number, with zeros added to the empty places. Start with 00101101200101101_2001011012, which is 454545 in decimal:
- Shift left one place: 001011012→01011010200101101_2 \rightarrow 01011010_2001011012→010110102. The result is 909090, or 45×245 \times 245×2.
- Shift right two places: 001011012→00001011200101101_2 \rightarrow 00001011_2001011012→000010112. The result is 111111, the whole-number part of 45÷4=11.2545 \div 4 = 11.2545÷4=11.25.
On the right shift, bits that move beyond the end are lost. The original number satisfies 45=11×4+145=11\times4+145=11×4+1, so the lost bits account for the remainder of 111. Zeros enter from the left, but they do not preserve that remainder in the stored result.
Bits can also be lost on a left shift. For example, shifting the unsigned 888-bit number 11001000211001000_2110010002 left one place stores 10010000210010000_2100100002, or 144144144, rather than 200×2=400200\times2=400200×2=400. The leading bit has moved beyond the available space: this is overflow.
The exam mistake to avoid is saying that a right shift always gives the exact answer to division. For an unsigned whole number, it gives the whole-number quotient; any remainder is discarded. Also check how many bits are available before assuming a left shift gives the full product.