Two's Complement Calculator
See step by step how a negative number becomes two's complement, and find the signed value of any bit pattern.
The binary field uses the number of digits you type as its width, so 1011 is read as 4 bits.
How to form two's complement
For −n, write n in binary, invert every bit and add 1. This lets an adder do subtraction, which is why CPUs and ALUs use it. N bits cover −2N−1 to 2N−1−1.
Worked example: −5 in 8-bit two's complement
- Write the magnitude 5 in 8 bits: 0000 0101
- Invert every bit: 1111 1010
- Add 1: 1111 1011 = 0xFB
- Check: 1111 1011 + 0000 0101 = 1 0000 0000 → drop the carry and you get 0
4-bit two's complement table
| Bit pattern | 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 number of bits
| Bits | Signed range | Unsigned range |
|---|---|---|
| 4 | -8 ~ 7 | 0 ~ 15 |
| 8 | -128 ~ 127 | 0 ~ 255 |
| 16 | -32,768 ~ 32,767 | 0 ~ 65,535 |
| 32 | -2,147,483,648 ~ 2,147,483,647 | 0 ~ 4,294,967,295 |
Frequently asked questions
What is −1 in 8-bit two's complement?
1111 1111 (0xFF). Write 1 as 0000 0001, invert it to 1111 1110 and add 1.
How can I tell if a two's complement number is negative?
Look at the leftmost bit. If it is 1, the number is negative, and its value is the unsigned value minus 2 to the power of the bit width.