Two's Complement Calculator
This two's complement calculator turns a negative number into binary, or reads a two's complement number back as decimal. Pick 4, 8, 16 or 32 bits and it shows each step: write the number, invert every bit, add 1.
Two's complement
Two's complement
How to find the two's complement
- 01
Write the number in binary
Leave out the minus sign and pad to the full width: 5 in 8 bits is
00000101. - 02
Invert every bit
Every 0 becomes 1 and every 1 becomes 0:
11111010. - 03
Add 1
11111010 + 1is11111011, which is −5 in 8-bit two's complement.
Reading two's complement
If the leftmost bit is 0, the number is positive: read it as plain binary. If it is 1, the number is negative: invert every bit, add 1, and put a minus sign in front. 11111011 inverts to 00000100, plus 1 is 00000101, so it is −5.
Another way: the leftmost bit is worth minus its usual value. In 8 bits it is worth −128, so 11111011 is −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5.
4-bit two's complement table
All 16 patterns of 4 bits, read as unsigned and as two's complement. Four bits hold −8 to 7.
| Binary | Unsigned | Two's complement |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | -8 |
| 1001 | 9 | -7 |
| 1010 | 10 | -6 |
| 1011 | 11 | -5 |
| 1100 | 12 | -4 |
| 1101 | 13 | -3 |
| 1110 | 14 | -2 |
| 1111 | 15 | -1 |
Range by width
| Bits | Smallest | Largest |
|---|---|---|
| 4 | −8 | 7 |
| 8 | −128 | 127 |
| 16 | −32,768 | 32,767 |
| 32 | −2,147,483,648 | 2,147,483,647 |
Frequently asked questions
What is two's complement?
Two's complement is how computers store negative whole numbers. The leftmost bit is the sign: 0 for positive, 1 for negative. The same adding circuit then works for positive and negative numbers, which is why nearly every processor uses it.
How do you find the two's complement of a number?
Write the number in binary at the chosen width, invert every bit, then add 1. For −12 in 8 bits: 12 is 00001100, inverted is 11110011, plus 1 is 11110100.
How do you convert two's complement to decimal?
If the first bit is 0, read it as plain binary. If it is 1, invert every bit, add 1, and make the result negative: 1110 inverts to 0001, plus 1 is 0010, so it is −2.