Syllabus & Goals 3 min
Cambridge 1.1 · Number systems Paper 1 · Computer Systems
By the end of this lesson you can:
- Add two positive 8-bit binary numbers and identify an overflow.
- Carry out a logical shift and state its effect (× 2 or ÷ 2).
- Use two's complement to represent negative 8-bit numbers.
Recap / Warm-Up 5 min
You can now convert between binary, denary and hex. Next we do arithmetic on binary numbers.
Quick starter
In denary, what is the largest number you can show with three digits? What happens if you add 1 to it?
Reveal the answer
999 is the largest; 999 + 1 = 1000 needs a fourth digit. A computer with a fixed number of bits has the same problem — that "extra digit" is called overflow.
Key Concept 14 min
1 · Binary addition
There are only four rules to learn:
| Sum | Result |
|---|---|
| 0 + 0 | 0 |
| 0 + 1 | 1 |
| 1 + 1 | 0, carry 1 |
| 1 + 1 + 1 | 1, carry 1 |
Add column by column from the right, carrying a 1 whenever the total is greater than 1 — exactly like carrying in denary.
2 · Overflow
An 8-bit register can hold 0 to 255 (that is 2⁸ − 1). If an addition needs a 9th bit, the answer is too big to store — this is an overflow error.
3 · Logical shifts
A logical shift moves every bit left or right. Empty positions are filled with 0.
- Shift left by 1 place = multiply by 2.
- Shift right by 1 place = divide by 2.
4 · Two's complement (negative numbers)
So far every number has been positive. To store negative numbers we change just one heading: the left-most bit becomes −128.
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 |
This number is −128 + 16 + 2 + 1 = −109. The range becomes −128 to +127.
Worked Example 12 min
(a) Add 00100111 + 01001010
0 0 1 0 0 1 1 1 + 0 1 0 0 1 0 1 0 ----------------- 0 1 1 1 0 0 0 1 (carries: 1 1 1)
Answer: 01110001 = 64 + 32 + 16 + 1 = 113. (Check: 39 + 74 = 113. ✓)
(b) Convert −67 to two's complement (invert + add 1)
| Step | Result |
|---|---|
| Write +67 in binary | 01000011 |
| Invert every bit (swap 0s and 1s) | 10111100 |
| Add 1 | 10111101 |
Check: −128 + 32 + 16 + 8 + 4 + 1 = −67. ✓
Shifts as code
Cambridge pseudocode
// A logical shift LEFT multiplies by 2; a shift RIGHT divides by 2 DECLARE Value, Result : INTEGER Value ← 21 Result ← Value * 2 OUTPUT "Shift left once gives ", Result Result ← Value DIV 2 OUTPUT "Shift right once gives ", Result
The same idea in Python (IDLE)
# In Python << shifts left (x2) and >> shifts right (/2) value = 21 print("Shift left once =", value << 1) print("Shift right once =", value >> 1)
Output
Shift left once = 42 Shift right once = 10
Try It Yourself 12 min
Goal: Add the 8-bit numbers 00011101 + 01100110.
Hint: work right to left, carrying a 1 whenever a column totals 2 or 3.
Goal: Take 00010101 (21) and perform a logical shift two places left. What denary value do you get, and why?
Goal: Write −45 as an 8-bit two's complement binary number. Use the invert-and-add-1 method.
📝 Exam Practice 10 min
Define the term overflow error.
Mark scheme
- When the result of a calculation is too large for the number of bits / register available (1).
The register 00010110 undergoes a logical shift one place to the left. Show the result and give its denary value.
Mark scheme
- Result
00101100(1). - Denary 44 — i.e. 22 × 2 (1).
State the denary value of the two's complement number 11110101.
Mark scheme
- −128 + 64 + 32 + 16 + 4 + 1 =
−11(1).
Recap & Key Terms 3 min
Add binary column by column, carrying past 1; a 9th bit means overflow. A logical shift left multiplies by 2 and right divides by 2, filling gaps with 0. Two's complement stores negatives by making the top bit worth −128.
- Overflow error
- A result too large for the available bits (e.g. a 9th bit in 8-bit addition).
- Logical shift
- Moving all bits left or right; empty positions are filled with 0. Left = × 2, right = ÷ 2.
- Most significant bit (MSB)
- The left-most bit; in two's complement it carries the −128 (sign) value.
- Two's complement
- A method of storing negative binary numbers; a leading 1 means the value is negative.
Homework 1 min
Task (≤ 15 min): (a) Add 01101110 + 11011110 and say what happens. (b) Convert −79 to 8-bit two's complement.
Model answer
- (a) The sum needs a 9th bit → overflow error; the 8-bit answer
01001100is incorrect (110 + 222 = 332 > 255). - (b) 79 =
01001111→ invert10110000→ add 1 →10110001(= −128 + 32 + 16 + 1 = −79).