Number Systems · Cambridge syllabus 1.1 · Lesson 5 of 5
Two's Complement
In eight-bit two’s complement, the highest place has weight −128 and the remaining places have positive weights 64 through 1. Values range from −128 to 127. To negate a representable value, invert its bits and add one, retaining eight bits.
By the end, you can
- Understand why two's complement is used to represent positive and negative integers.
- Represent positive 8-bit integers using two's complement.
- Represent negative 8-bit integers using two's complement.
- Convert positive denary integers to 8-bit two's-complement representation.
- Convert negative denary integers to 8-bit two's-complement representation.
- Convert two's-complement binary to denary.
- Interpret the most significant bit as part of the signed representation.
Signed binary
Ordinary binary has no way of writing a negative number, so a convention is needed. Two’s complement is the one computers use.
The leftmost bit becomes a sign bit: 0 means positive and 1 means negative. In eight bits that leaves seven bits for the size, so the range is −128 to +127 rather than 0 to 255.
The leftmost column is treated as −128 instead of +128, and all the others keep their usual values. So 10000001 is −128 + 1 = −127, and 11111111 is −128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = −1.
The reason for this convention rather than a simpler one is that ordinary binary addition then works unchanged on negative numbers, so no separate subtraction circuit is needed. That is the answer to "why two’s complement".
Worth remembering
- Leftmost bit is the sign: 0 positive, 1 negative.
- Its column is worth −128 in an 8-bit number, so the range is −128 to +127.
- Chosen because ordinary addition then works on negatives too.
Two's-complement conversion
To convert a positive number to its negative two’s-complement form, there is a two-step method: flip every bit, then add 1.
Take +20, which is 00010100. Flipping gives 11101011. Adding 1 gives 11101100, which is −20. Check it by reading the place values: −128 + 64 + 32 + 8 + 4 = −20.
The same procedure converts back, which is worth knowing because it means you only ever learn one method. Flip 11101100 to get 00010011, add 1 to get 00010100, which is 20 — so the original was −20.
A quicker alternative: copy the bits from the right up to and including the first 1, then flip everything after that. It gives the same answer and is easier under time pressure.
Adding a number to its two’s complement gives zero within the available bits, with the carry discarded, which is the check that the conversion was right.
Worth remembering
- Flip all the bits, then add 1. The same method converts back.
- Check by reading the place values with the leftmost worth −128.
Worked example
−5: +5 is 00000101; invert to 11111010 and add one to get 11111011. Its value is −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
−128 + 64 + 32 + 16 = −16.
Check your method, units and explanation against it.
Marked practice
Set 1 of 4 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.