Study Guide
Two’s Complement
How a computer stores negative whole numbers in binary by making the leftmost bit worth −128, how to convert both ways between denary or binary and 8-bit two’s complement, and the range it can store.
Lesson 1.5 Data Representation
For: Cambridge IGCSE Computer Science learners, or anyone who can already convert between binary and denary and has met overflow
Stage: Think
Going backwards past zero
A fictional toy car has a mileage counter with three wheels, showing 000 to 999. It shows 000, and the car is pushed one mile backwards, so the wheels roll back.
Think it through
What do the wheels show after one mile backwards? If the toy company agreed that this reading means −1, what would 998 mean?
- Hint 1: Which reading comes just before 000 on a wheel that rolls round?
Show what happens
The wheels show 999, which can be agreed to mean −1. Then 998 means −2, 997 means −3, and so on: the readings just below 1000 stand for numbers just below zero.
Think it through
In an 8-bit register, which pattern gives 0000 0000 when 0000 0001 is added to it, if the carry out of the leftmost column is lost? What number could that pattern stand for?
- Hint 1: Recall what 255 + 1 gave in the overflow lesson.
- Hint 2: Which number plus 1 gives 0?
Show what happens
1111 1111: adding 1 makes every column carry and leaves 0000 0000, just as the counter wraps from 999 to 000. A pattern that gives 0 when 1 is added behaves like −1, so 1111 1111 can stand for −1.
Stage: Discover
A column worth −128
The pattern 1111 1111 should stand for −1. But with the usual columns it is worth 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.
Think it through
The seven right-hand columns, 64 + 32 + 16 + 8 + 4 + 2 + 1, add up to 127. For 1111 1111 to be worth −1 in total, what would the leftmost column have to be worth?
- Hint 1: Write it as an equation: the leftmost column + 127 = −1.
Show what happens
−128: −128 + 127 = −1. So if the leftmost column is worth −128 instead of +128, the pattern 1111 1111 is worth −1 and every other pattern still gets a sensible value.
This is the two’s complement system. An 8-bit two’s complement number has the usual columns, except that the leftmost column, the most significant bit, is worth −128 and not +128:
From left to right, the eight columns are worth −128, 64, 32, 16, 8, 4, 2 and 1.
A number that starts with 0 is positive: it is read in the ordinary way. A number that starts with 1 is negative, because the −128 is included.
- Write the bits under the columns. 1011 0100 has 1s in the −128, 32, 16 and 4 columns.
- Add the values of the columns that hold a 1. −128 + 32 + 16 + 4.
- Add the positive columns first, then the negative one. 32 + 16 + 4 = 52, and −128 + 52 = −76.
- Check the sign. The leftmost bit is 1, so the number should be negative. It is.
Check your understanding
Show the answer
Answer: B. −123, because the −128 column is on and 4 + 1 is added: −123.
−128 + 4 + 1 = −123.
| 8-bit two’s complement | Denary |
|---|---|
| 0000 1010 | 10 |
| 1111 1110 | |
| 1000 0001 | |
| 1100 1000 | |
| 0111 1111 | |
| 1000 0000 |
- Check the leftmost bit first: is the number positive or negative?
- Add the positive columns, then add the −128 if the leftmost bit is 1.
Show the completed table
| 8-bit two’s complement | Denary |
|---|---|
| 0000 1010 | 10 |
| 1111 1110 | −2 |
| 1000 0001 | −127 |
| 1100 1000 | −56 |
| 0111 1111 | 127 |
| 1000 0000 | −128 |
Stage: Predict
Writing a negative number
Think it through
Using the columns −128, 64, 32, 16, 8, 4, 2 and 1, each at most once, how could you make −45? Which column must you start with, and what is left to make after it?
- Hint 1: The answer is negative, so only one column can help to get there. Which?
- Hint 2: After that column, how far is −45 from −128?
Show a model answer
Start with −128, the only negative column. Then −45 − (−128) = 83 is left to make from the positive columns. 83 = 64 + 16 + 2 + 1, so the 64, 16, 2 and 1 columns are on. The pattern is 1101 0011, and −128 + 64 + 16 + 2 + 1 = −45.
There is also a shortcut that always works: to write the negative of a number, invert every bit (swap each 0 for 1 and each 1 for 0), then add 1.
- Write the positive number. 45 is 0010 1101.
- Invert every bit. 1101 0010.
- Add 1. 1101 0010 + 1 = 1101 0011.
- Check. The result is the same as the one made from the columns: 1101 0011.
Why does it work? A number and its inverted form add up to 1111 1111, because each column has one 0 and one 1: 0010 1101 + 1101 0010 = 1111 1111. But 1111 1111 is −1. So the inverted form is −1 minus the number, and adding 1 gives minus the number: −45.
Going back is the same: invert and add 1 again. 1101 0011 inverts to 0010 1100, and adding 1 gives 0010 1101, which is 45.
A positive number needs no change at all: it is written in ordinary binary with a 0 at the left. 37 is 0010 0101.
Check your understanding
Show the answer
Answer: C. 1110 1100, which is 20 inverted, then 1 added.
20 is 0001 0100. Inverting gives 1110 1011, and adding 1 gives 1110 1100. Check: −128 + 64 + 32 + 8 + 4 = −20.
| Denary | 8-bit two’s complement |
|---|---|
| −1 | 1111 1111 |
| 37 | |
| −12 | |
| −100 | |
| −128 |
- Positive numbers are ordinary binary with a 0 on the left.
- For a negative number: write the positive form, invert every bit, then add 1. Check by adding the columns, with −128.
Show the completed table
| Denary | 8-bit two’s complement |
|---|---|
| −1 | 1111 1111 |
| 37 | 0010 0101 |
| −12 | 1111 0100 |
| −100 | 1001 1100 |
| −128 | 1000 0000 |
Stage: Explain
How far the numbers go
Think it through
In 8-bit two’s complement, what is the largest number you can write, and the smallest (the most negative)? Which patterns are they?
- Hint 1: For the largest, the −128 column must be off. Switch on all the others.
- Hint 2: For the smallest, which single column makes the biggest negative contribution, and should any positive column also be on?
Show what happens
The largest is 0111 1111 = 127 (the −128 column off, all the others on). The smallest is 1000 0000 = −128 (only the −128 column on).
The range of 8-bit two’s complement is −128 to 127. That is 256 different whole numbers, one for each pattern of eight bits. There is one more negative number than positive ones, because zero uses one of the patterns that start with 0.
A number outside the range cannot be stored. In a register, adding 1 to 0111 1111 (127) gives 1000 0000, which reads as −128: just as an unsigned register wraps from 255 to 0, a two’s complement register wraps from 127 to −128.
Check your understanding
Show the answer
Answer: A. −128 to 127
−128 to 127 contains 128 negative numbers, zero and 127 positive numbers: 256 numbers in all, the same as the 256 patterns of eight bits.
Stage: Discover
Binary numbers with a sign
So far each negative number has been written in denary. A number can also be written in binary with a minus sign in front: −1011 means minus 11 (−(8 + 2 + 1)).
Think it through
How could you store −1011 (minus 11) in an 8-bit register? Write down your plan for the pattern, and then try it.
- Hint 1: Write the number without its sign as 8 bits first. Then use the invert-and-add-1 method.
Show a model answer
Write 1011 as eight bits: 0000 1011. Invert: 1111 0100. Add 1: 1111 0101. Check: −128 + 64 + 32 + 16 + 4 + 1 = −11.
| Number | 8-bit two’s complement |
|---|---|
| −1011 | 1111 0101 |
| +101101 | |
| −101101 | |
| −1100 |
- Fill the number out to eight bits with leading zeros, ignoring the sign.
- If the number is negative, invert the bits and add 1.
Show the completed table
| Number | 8-bit two’s complement |
|---|---|
| −1011 | 1111 0101 |
| +101101 | 0010 1101 |
| −101101 | 1101 0011 |
| −1100 | 1111 0100 |
Now the other way: read the denary value, then write it as binary with a sign. For a negative number, invert and add 1 to find the size, and put the minus sign in front. Write positive numbers without leading zeros.
| 8-bit two’s complement | Denary | Binary with a sign |
|---|---|---|
| 1111 0100 | −12 | −1100 |
| 1110 0111 | ||
| 0101 0110 | ||
| 1000 1100 |
- Read the denary value with the −128 column first.
- Then write the size of the number in binary, with a minus sign if it is negative.
Show the completed table
| 8-bit two’s complement | Denary | Binary with a sign |
|---|---|---|
| 1111 0100 | −12 | −1100 |
| 1110 0111 | −25 | −11001 |
| 0101 0110 | 86 | 1010110 |
| 1000 1100 | −116 | −1110100 |
Stage: Apply
Use it somewhere new
A fictional weather station stores each temperature in degrees Celsius as an 8-bit two’s complement number. A reading arrives as 1110 0111.
Apply it
Show the answer
Answer: D. −25 °C, because −128 + 64 + 32 + 4 + 2 + 1 = −25.
−128 + 64 + 32 + 4 + 2 + 1 = −128 + 103 = −25. It is a cold reading, which is why the leftmost bit is a 1.
A fictional freezer logger stores its temperature in the same way, and needs to record −18 °C.
Apply it
Show the answer
Answer: B. 1110 1110, which is 18 inverted, then 1 added.
18 is 0001 0010. Inverting gives 1110 1101 and adding 1 gives 1110 1110. Check: −128 + 64 + 32 + 8 + 4 + 2 = −18.
Apply it
Show the answer
Answer: C. −128, because 0111 1111 + 1 = 1000 0000, which reads as −128.
0111 1111 + 0000 0001 = 1000 0000, and in two’s complement 1000 0000 is −128. The true answer, 128, is outside the range −128 to 127, so the stored result is wrong.
Apply it
Show the answer
Answer: A. The leftmost bit is not a minus sign: it is a column worth −128, so 1000 0000 is −128.
1000 0000 has only the −128 column on, so its value is −128. In two’s complement the leftmost bit is part of the value, not a sign in front of it.
Stage: Consolidate
Bring it together
Think it through
Without looking back, explain to a friend how to find the 8-bit two’s complement pattern for −9, and how you could check your answer.
Show a model answer
9 is 0000 1001. Invert every bit: 1111 0110. Add 1: 1111 0111. To check, add the columns: −128 + 64 + 32 + 16 + 4 + 2 + 1 = −128 + 119 = −9.
Check your understanding
Show the answer
Answer: C. 256, one for each pattern of eight bits.
Eight bits always make 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256 patterns. Two’s complement shares them out as −128 to 127.
Go deeper Beyond the specification: why computers like two’s complement
Adding a positive and a negative two’s complement number needs no special rules: it is the same column addition as before. For example, 10 + (−5): 0000 1010 + 1111 1011 = 1 0000 0101. Drop the carry out of the leftmost column and the register holds 0000 0101, which is 5. The carry out is simply dropped in two’s complement addition, and the answer is correct as long as it lies in the range −128 to 127. Subtraction can then be done by adding the negative. This is one reason nearly every computer uses it.
- Two’s complement stores negative numbers in binary by making the leftmost column worth −128 (in 8 bits). The other columns are the usual 64, 32, 16, 8, 4, 2 and 1.
- A number whose leftmost bit is 0 is positive, and is read as ordinary binary. A leftmost bit of 1 means the −128 is included, so the number is negative.
- To read a number, add the values of the columns that hold a 1, with −128 for the leftmost. To write a negative number, either make it from the columns, or write the positive form, invert every bit and add 1. Inverting and adding 1 also turns a negative pattern back into its positive form.
- The 8-bit range is −128 to 127: 256 numbers, one for each pattern. Outside it, the register wraps round and overflows.
- The leftmost bit is not a minus sign in front of a number: it is a column with a value of its own.
Sources and scope
- What this lesson is. The fifth lesson of the Data Representation module, written for this site. It teaches point 6 of Cambridge IGCSE Computer Science 1.1 (8-bit two’s complement) against the 2026 to 2028 syllabus (version 6). Its curriculum links are provisional: no link has been verified by the site owner. They show where the lesson may help with a course and imply no review or endorsement by any examination board.
- Original material. The toy car’s mileage counter, the weather station, the freezer logger and Aisha’s claim are fictional examples written for this lesson.
- Simplified on purpose. Only 8-bit two’s complement is taught; other word lengths follow the same pattern with a different leftmost column. Other ways of storing negative numbers, such as sign and magnitude and one’s complement, are not taught. The optional extension on adding negative numbers goes beyond what 0478 point 6 asks for.
The number system with only two digits, 0 and 1, in which each column is worth twice the column to its right.
A single binary digit: 0 or 1. The smallest unit of data a computer stores.
The everyday number system with ten digits, 0 to 9, in which each column is worth ten times the column to its right.
The bit at the left-hand end of a binary number, which is worth the most.
What happens when a calculation produces a value too big for the register that has to store it, so the result stored is wrong.
A very small, very fast storage location inside the CPU that holds a fixed number of bits: the address, data or instruction the CPU is working on at that moment.
A setting that changes how adventurous a model’s choice of the next token is: low means it nearly always picks the most likely token, high spreads its choices.
A way of storing positive and negative whole numbers in binary, in which the left-hand bit is worth a negative amount (−128 in an 8-bit number).
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.