CS2 — Two's Complement
- I can explain why two's complement is used to represent negative integers in binary
- I can convert a negative denary integer to two's complement binary using the invert-and-add-1 method
- I can convert a two's complement binary number back to denary
- I can state and calculate the range of values storable using n bits in two's complement
- I can identify a negative two's complement number by its leading 1 bit
- I can correctly apply invert-and-add-1, including when carries chain across multiple bits
- I can state that 8-bit two's complement stores −128 to +127 and explain why the range is asymmetric
- I can calculate min/max values for any bit width using −2(n−1) to 2(n−1)−1
Key vocabulary
The problem with negative numbers
Computers need negative numbers constantly — temperatures, bank balances, coordinate offsets, and error codes all require them. The problem is that a computer only has 1s and 0s to work with. You cannot simply write a minus sign in binary.
An obvious first attempt is sign-and-magnitude: use the leftmost bit as a plus/minus flag, and the remaining bits to store the magnitude. This creates two immediate problems. First, you now have two different representations of zero (positive zero and negative zero) which wastes a bit pattern and makes comparisons awkward. Second, binary addition breaks — adding +3 and −3 with sign-and-magnitude hardware does not produce zero.
Two's complement solves both problems elegantly. It uses the same hardware addition for positive and negative numbers, has exactly one representation of zero, and is used in virtually every modern processor.
How two's complement works
The key insight is that the most significant bit (MSB) — the leftmost bit — carries a negative place value. Every other bit keeps its normal positive place value.
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
|---|---|---|---|---|---|---|---|
| −2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The −128 column (highlighted) is the sign bit. When it is 1, you subtract 128 rather than adding 128. When it is 0, the number is positive and works exactly as before.
To find the value of any 8-bit two's complement number: write it under the table, add up all columns with a 1 (treating the leftmost column as −128).
Examples of place value arithmetic
00000000→ 0 (all zeros = zero)01111111→ 64+32+16+8+4+2+1 = +127 (largest positive)10000000→ −128+0 = −128 (most negative)11111111→ −128+64+32+16+8+4+2+1 = −1
Converting denary to two's complement
Positive numbers: convert exactly as in CS1. The MSB will be 0, confirming positive.
Negative numbers: use the invert-and-add-1 method.
- Write the positive version of the number in the full bit width (e.g. 8 bits)
- Invert every bit (0s become 1s, 1s become 0s)
- Add 1 to the result
Why does this work? Inverting a number n gives −(n+1) in two's complement. Adding 1 then gives −n. The method is purely mechanical — you do not need to understand the algebra to apply it correctly.
Converting two's complement back to denary
Look at the MSB (leftmost bit):
- MSB = 0 → positive number. Convert normally (sum of place values).
- MSB = 1 → negative number. Use the place value table, treating the leftmost column as −128.
In both cases, write the binary number under the place value table and add up all columns with a 1.
Range of values
With n bits in two's complement, the range is:
- Minimum: −2(n−1)
- Maximum: 2(n−1) − 1
| Bit width (n) | Minimum | Maximum | Total values |
|---|---|---|---|
| 4 bits | −8 | +7 | 16 |
| 8 bits | −128 | +127 | 256 |
| 16 bits | −32,768 | +32,767 | 65,536 |
| 32 bits | −2,147,483,648 | +2,147,483,647 | 4,294,967,296 |
💡 The negative side has 128 states (−128 to −1) while the positive side has only 127 states (1 to 127) because zero takes one of the positive bit patterns (00000000).
Why is the range asymmetric?
Zero is represented as 00000000, which occupies one of the positive bit patterns. With 8 bits there are 256 patterns total: one is zero, 127 are positive (1 to 127), and 128 are negative (−128 to −1). Zero takes a slot that would otherwise be +128, which is why there are 128 negative values but only 127 positive ones.
Worked examples
00011001
(+25 in 8 bits)
11100110
(represents −26)
11100111
Answer: −25 ✓
00011001Check: 16+8+1 = 25 ✓
00011001 → 1110011011100110 + 1 = 11100111Verify: −128+64+32+4+2+1 = −128+103 = −25 ✓
−128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 1 | 1 | 1 | 1 | 0 | 1 | 1 | 00000000100000001 → 1111111011111110 + 1 = 11111111Verify: −128+64+32+16+8+4+2+1 = −128+127 = −1 ✓
Note: 11111111 = −1 in two's complement, NOT 255. Context matters — the same bit pattern means different things depending on whether the system uses signed or unsigned binary.
11111111
- Wrong bit width. Always use the full width specified. For 8-bit −25, write 00011001 (8 bits) before inverting — not 11001 (5 bits). Inverting a 5-bit number produces a completely wrong 8-bit result.
- Forgetting to add 1, or carry chain errors. After inverting you must add 1. When the add causes a carry chain (e.g. 11111110 + 1), work right to left carefully. Forgetting the +1 is the most common error in exam scripts.
- Using +128 instead of −128 when converting back. The leftmost column is −128, not +128. Treating 11000000 as 128+64 = 192 instead of −128+64 = −64 costs the mark every time.
- Confusing signed and unsigned. 11111111 = 255 as an unsigned 8-bit number, but −1 in two's complement. Always check whether the question specifies signed or unsigned binary before converting.
11111111
Two's complement appears in every Higher Computing past paper — typically worth 1–2 marks and completely mechanical. There is no trick, only method. Always show working. The place value check step takes 20 seconds and catches errors before they cost marks.
Expect these question forms:
- "Convert −X to 8-bit two's complement" (1 mark)
- "Convert XXXXXXXX two's complement to denary" (1 mark)
- "State the range for n-bit two's complement" (1 mark)
- "Explain why the range is asymmetric" (2 marks)
Task Set A
Task Set B
0.1 + 0.2 does not equal exactly 0.3. Using your knowledge of binary, explain why.Higher Computing Science → Computer Systems → CS2
Timing (120 min double):
5 min — warm up independently, circulate
5 min — key vocabulary together
10 min — why negative numbers (class discussion: "how would you store −5?")
15 min — method: work Examples 1 and 2 together on board, pupils attempt Example 3 before reveal
5 min — range of values and asymmetry
5 min — Now you try (independent then reveal)
5 min — common mistakes ("has anyone made this one just now?")
25 min — tasks
5 min — cold call review
Watch for: wrong bit width (most common); carry chain errors in Step 3; using +128 instead of −128 when converting back to denary.
C2 is worth doing as a whole-class demo if time allows — showing that +25 + (−25) = 0 using ordinary binary addition demonstrates elegantly why two's complement became universal.