Computer Systems · Data Representation

CS2 — Two's Complement

📅 Thu 4 Jun 2026 · P3+P4 (double)
~120 minutes
Learning intentions
Success criteria
Warm up — recap from CS1
Answer from memory · check when done
W1
Convert 10110101 to denary.
W2
Convert 73 to 8-bit binary.
W3
How many different values can be stored in 8 bits?
W4
What is the largest positive integer 8-bit unsigned binary can represent?
W5
A system uses 10-bit binary. What is the largest positive integer it can store?

Key vocabulary

Two's complement
A method of representing positive and negative integers in binary using a sign bit
Sign bit
The most significant (leftmost) bit, indicating positive (0) or negative (1)
Most significant bit (MSB)
The leftmost bit — the one with the highest place value
Invert
Flip every bit: 1s become 0s, 0s become 1s
Range
The spread of values representable with a given bit width
Asymmetric range
In two's complement, there is one more negative value than positive values
Overflow
When a result falls outside the storable range for the given bit width

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 7Bit 6Bit 5Bit 4 Bit 3Bit 2Bit 1Bit 0
−2⁷2⁶2⁵2⁴ 2⁰
−128643216 8421
Bit 7 (MSB) 1 = Negative (−128)
Bits 6–0 Normal positive combinations (+1 to +127)

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

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.

  1. Write the positive version of the number in the full bit width (e.g. 8 bits)
  2. Invert every bit (0s become 1s, 1s become 0s)
  3. 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):

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:

Bit width (n)MinimumMaximumTotal values
4 bits−8+716
8 bits−128+127256
16 bits−32,768+32,76765,536
32 bits−2,147,483,648+2,147,483,6474,294,967,296
8-bit two's complement spectrum
−128 10000000
0 00000000
+127 01111111

💡 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

Step 1
Positive base 00011001 (+25 in 8 bits)
↓ Invert every bit (0 ⇄ 1)
Step 2
After inversion 11100110 (represents −26)
↓ Add 1 to the binary string
Step 3
Final result 11100111 Answer: −25 ✓
Example 1 — Convert −25 to 8-bit two's complement
1
Write +25 in 8-bit binary: 00011001
Check: 16+8+1 = 25 ✓
2
Invert every bit: 0001100111100110
3
Add 1: 11100110 + 1 = 11100111
Answer: 11100111
Verify: −128+64+32+4+2+1 = −128+103 = −25
Example 2 — Convert 11110110 to denary (two's complement)
1
MSB = 1 → this is a negative number. Use the place value table with −128 in the leftmost column.
2
Write under the table:
−128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
   1  | 1 |  1 |  1 | 0 | 1 | 1 | 0
3
Add columns with a 1: −128 + 64 + 32 + 16 + 4 + 2 = −128 + 118
Answer: −10
Example 3 — Convert −1 to 8-bit two's complement
1
Write +1 in 8-bit binary: 00000001
2
Invert every bit: 0000000111111110
3
Add 1: 11111110 + 1 = 11111111
Answer: 11111111
Verify: −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.
Same bits — different meaning depending on context 11111111
Unsigned binary 255
Two's complement (signed) −1
Now you try
Convert −14 to 8-bit two's complement. Show all three steps, then verify your answer using the place value table.
⚠️ Common mistakes — examiner feedback
Same bits — different meaning depending on context 11111111
Unsigned binary 255
Two's complement (signed) −1
📝 Exam tip

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:

Task Set A

Task Set A — Higher core
B1
Convert −37 to 8-bit two's complement. Show your working.
B2
Convert −128 to 8-bit two's complement.
B3
Convert 10110100 to denary. (Treat as 8-bit two's complement.)
B4
Convert 01101011 to denary. (Treat as 8-bit two's complement.)
B5
What is the minimum value that can be stored using 6-bit two's complement?
B6
What is the maximum value that can be stored using 6-bit two's complement?
B7 — past paper style (2 marks)
Explain why the range of values in two's complement is asymmetric.
B8 — past paper style (1 mark)
State the range of values that can be stored using 16-bit two's complement.
B9
A temperature sensor records −5°C. This is stored as 8-bit two's complement. Which binary value is correct?
B10 — past paper style (2 marks)
Describe how to represent −19 in 8-bit two's complement. Show all working.
✅ Higher checkpoint — B7 (asymmetric range) and B10 (full working) are the most exam-relevant. Confident on both = ready for prelim and SQA exam.

Task Set B

Task Set B — Extension · Beyond the specification
C1
In most programming languages, 0.1 + 0.2 does not equal exactly 0.3. Using your knowledge of binary, explain why.
C2
Add 8-bit two's complement +25 and −25 using binary addition. What result do you get, and why is this significant?
C3
Convert two's complement −25 (11100111) to hexadecimal. Explain why programmers find hexadecimal useful when working with binary data.
📁 File this in OneNote under:
Higher Computing Science → Computer Systems → CS2
📌 Teacher notes — not for pupils

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.