Number Systems
Data Representation
So far every binary number has been unsigned, meaning all the bits represent positive values. To store negative numbers, the syllabus uses , an 8-bit format where the leftmost bit's place value is negative.
The key idea
In an 8-bit two's complement value, the column headings are:
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|
Notice the leftmost column is −128, not +128. The other columns keep their normal positive values. The leftmost bit is therefore the sign bit: if it is 0, the number is positive (or zero); if it is 1, the number is negative.
The range of 8-bit two's complement
| Bit pattern | Denary value |
|---|---|
| 00000000 | 0 |
| 01111111 | +127 (the largest positive value) |
| 10000000 | −128 (the smallest negative value) |
| 11111111 | −1 |
So the range is −128 to +127 inclusive.
Reading a two's complement number
To find the denary value of a two's complement number, sum every column heading whose bit is set to 1, treating the leftmost column as −128.
Writing a negative number in two's complement
The fastest method on paper is the copy-and-invert trick:
- Write the positive equivalent of the number in 8-bit binary.
- Working from the right-hand end, copy each bit unchanged until you have written down the first 1 you meet (the 1 itself is also copied).
- Invert every bit to the left of that 1 (turn 0s into 1s and 1s into 0s).
Alternative method: invert all bits and add 1
A second standard method gives the same answer:
- Write the positive equivalent in 8-bit binary.
- Invert every bit (flip 0 ↔ 1). This gives the one's complement.
- Add 1 to the result. The final 8-bit value is the two's complement.
Both methods are accepted in the exam; pick whichever you find easier and stick with it.
Common exam question
Converting to and from two's complement
Question: Convert a denary number to an 8-bit two's complement integer, convert a two's complement integer to denary, or name the system used to store negative integers (1–2 marks).
Asked in 5 of the 17 papers. A two-mark conversion is one mark for working and one for the answer, and the schemes' example of acceptable working is flip and add 1: show the positive value in 8-bit binary, every bit inverted, then the 1 added. From two's complement to denary, the same steps on the bit pattern give the magnitude, and the second mark is for the denary value, minus sign included.
Read the sign before you start. Two papers asked for a positive number in two's complement, and the answer is its ordinary 8-bit binary with 0 as the sign bit (where working is marked, it is the conversion to binary); flipping it would make it negative. The one-mark naming question's answer is two's complement.
Worked example
Converting a negative denary number to two's complement
Express −90 as an 8-bit two's complement integer.
Solution:
- Write the positive equivalent in 8-bit binary: 90 = 64 + 16 + 8 + 2 = 01011010
- Invert every bit (one's complement): 10100101
- Add 1 to the one's complement: 10100101 + 1 = 10100110
- Result: 10100110 (which represents −90 in 8-bit two's complement)
Check: −128 + 32 + 4 + 2 = −90 ✓
Why two's complement is used
Two's complement is the dominant way of storing signed integers in modern computers because:
- One representation for zero. Some other schemes (like sign-and-magnitude) have both a +0 and a −0, wasting a bit pattern. Two's complement has only one 0.
- Addition works the same for positive and negative numbers. The CPU can use one binary adder for both signed and unsigned arithmetic; no special "subtract" hardware is needed.
- Negative numbers behave naturally. Adding a number and its negative gives 0 (with the carry-out discarded), exactly as expected.
Quick check
4 short questions on this note. See what has stuck, and where to look if something hasn't.