Binary arithmetic and shifts
Computers add, subtract, multiply and divide using binary. AQA's GCSE focuses on three things: 8-bit binary addition, binary shifts (left and right), and recognising overflow.
8-bit binary addition
Add bits column by column, right-to-left, just like decimal — but with the rules:
| A | B | A+B | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1+1+1 (with carry-in) | 1 | 1 |
Worked example: 01101010 + 00010111.
0 1 1 0 1 0 1 0
+ 0 0 0 1 0 1 1 1
---------------
1 0 0 0 0 0 0 1
carries: 1 1 1 1 1
Result: 10000001 (= 129 decimal). Verify: 106 + 23 = 129. ✓
Overflow
The result of an 8-bit addition has at most 8 bits. If the carry "spills off" the most significant bit, the answer can't be represented in 8 bits — this is overflow.
Worked example: 11111111 + 00000001.
1 1 1 1 1 1 1 1
+ 0 0 0 0 0 0 0 1
---------------
1 0 0 0 0 0 0 0 0
The 9th bit (1) is dropped, giving 8-bit result 00000000. The hardware sets an overflow flag to signal this.
In an exam, when you spot the carry leaving the MSB column, write "overflow" — the answer is wrong (or wraps around) without more bits.
Binary shifts
A shift moves all bits left or right by a stated number of places, filling the gap with 0.
Left shift
Each left shift multiplies by 2.
00010110 << 1 = 00101100 (22 → 44)
00010110 << 2 = 01011000 (22 → 88)
Why? Each bit's place value doubles when it moves one column to the left.
Right shift
Each right shift divides by 2, discarding any remainder.
01100100 >> 1 = 00110010 (100 → 50)
01100100 >> 2 = 00011001 (100 → 25)
01100100 >> 3 = 00001100 (100 → 12, integer division of 12.5)
The bit shifted off the right end is lost — that's why right shifts of odd numbers lose precision.
✦Worked example— Worked example — multiply by 8
Multiply 13 by 8 using shifts. 13 = 00001101. 00001101 << 3 (= shift left by 3 = × 8) = 01101000 = 64 + 32 + 8 = 104. ✓
✦Worked example— Worked example — overflow with shift
Left-shift 11000000 by 1: the 1 in the MSB is lost.
11000000 << 1 → 10000000 (with overflow — original MSB lost)
192 × 2 should be 384 but we get 128. The shift caused overflow.
Why hardware uses shifts
Multiplication by powers of 2 by shifting is vastly faster than full multiplication — it's a simple bit movement, no adder required. Compilers optimise multiplications by known powers of 2 to shifts automatically.
⚠Common mistakes— Pitfalls
- Forgetting the carry chain. Bits 1+1+1 → write 1, carry 1.
- Treating right shift like floor division and being surprised by integer-only result. 5 >> 1 = 2, not 2.5.
- Ignoring overflow. A 1 leaving the MSB column means the result needs more bits.
- Wrong direction shift. Left = ×2, Right = ÷2 — easy to confuse.
- Forgetting to fill with 0. Logical shifts always insert a 0 in the vacated bit; arithmetic shift on signed numbers fills differently (beyond GCSE).
✦Worked example— Worked example — full 8-bit add with overflow
Add 10000001 + 10000010.
1 0 0 0 0 0 0 1
+ 1 0 0 0 0 0 1 0
---------------
1 0 0 0 0 0 0 1 1
The leading 1 is the 9th bit — overflow. The 8-bit result wraps to 00000011.
➜Try this— Quick check
Compute 00111011 + 00010100 and state if there's overflow.
0 0 1 1 1 0 1 1
+ 0 0 0 1 0 1 0 0
---------------
0 1 0 0 1 1 1 1
Result: 01001111 (= 79). No carry past the MSB → no overflow.
AI-generated · claude-opus-4-7 · v3-deep-computer-science