AQA GCSE Computer Science (8525), section 3.3.4 (Binary arithmetic)
What a binary shift is
A binary shift moves every bit of a binary number a number of places left or right. Gaps are filled with 0s, and bits shifted off the end are lost. At GCSE you only use logical shifts with up to 8 bits.
Shift left
Moving bits left makes the number bigger. Each place multiplies by 2.
Shift 0000 1101 (13) left by 2:
Shift right
Moving bits right makes the number smaller. Each place divides by 2 (ignoring any remainder).
Shift 0000 1101 (13) right by 2:
The two bits 01 that moved off the right are lost.
Summary
| Shift | Effect |
|---|---|
| left by places | multiplies by |
| right by places | divides by (whole number) |
Losing bits
Shifting left can push a 1 off the end and give the wrong answer. For example, 1011 0110 shifted left by 1 becomes 0110 1100: the leading 1 is lost.
Where shifts are used
- Fast multiplication and division by powers of 2, which is quicker for a processor than full multiplication.
- Moving bits into position when packing data.
Common mistake: shifting the wrong way, or adding zeros at the wrong end. When you shift left, the new 0s appear on the right; when you shift right, the new 0s appear on the left. Also remember that bits pushed off the end are lost.
Exam tip: write the original number and draw the answer underneath with the correct number of places. Say what the shift does: "shifting left by 3 multiplies by 8".
Check yourself
What is the effect of shifting a binary number left by 1 place?
It multiplies the number by 2.
Shift 0000 1100 right by 2 places.
0000 0011.
Give one use of binary shifts.
Quickly multiplying or dividing by a power of 2.