Two’s Complement Calculator
Decimal ↔ two’s complement binary for 4 to 64 bits, with hex, one’s complement and every step.
Computed in your browser — nothing is sentConvert decimal numbers to two’s complement binary — and back — step by step
Step by step
How two’s complement works
Quick answer: to write a negative number in two’s complement, take its absolute value in binary using the full number of bits, invert every bit, and add 1. For −5 in 8 bits: 5 = 0000 0101 → invert → 1111 1010 → add 1 → 1111 1011. Positive numbers are ordinary binary padded with zeros, and the first bit is the sign: 0 for positive, 1 for negative. Reading one back is the same trick in reverse — if the first bit is 1, invert and add 1 to get the size, then put a minus sign in front.
n bits hold the values from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 — −128 to 127 in 8 bits — which is why the calculator checks the range for the width you pick. Computers use two’s complement because there is a single zero and ordinary binary addition works for negative numbers with no special cases: 5 + (−5) = 0000 0101 + 1111 1011 = 1 0000 0000, and the carry out of the top bit is simply dropped. The result also shows the pattern in hexadecimal (FB), what the same bits mean read as unsigned (251), and the one’s complement form. Everything runs in your browser.
4-bit two’s complement table
| Bits | Unsigned | Two’s complement | One’s complement |
|---|---|---|---|
| 0000 | 0 | 0 | 0 |
| 0001 | 1 | 1 | 1 |
| 0010 | 2 | 2 | 2 |
| 0011 | 3 | 3 | 3 |
| 0100 | 4 | 4 | 4 |
| 0101 | 5 | 5 | 5 |
| 0110 | 6 | 6 | 6 |
| 0111 | 7 | 7 | 7 |
| 1000 | 8 | −8 | −7 |
| 1001 | 9 | −7 | −6 |
| 1010 | 10 | −6 | −5 |
| 1011 | 11 | −5 | −4 |
| 1100 | 12 | −4 | −3 |
| 1101 | 13 | −3 | −2 |
| 1110 | 14 | −2 | −1 |
| 1111 | 15 | −1 | −0 |
Ranges by number of bits
| Bits | Smallest | Largest |
|---|---|---|
| 4 | −8 | 7 |
| 8 | −128 | 127 |
| 16 | −32,768 | 32,767 |
| 32 | −2,147,483,648 | 2,147,483,647 |
| 64 | −9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
Common mistakes
| Mistake | Why it is wrong | Instead |
|---|---|---|
| Inverting before padding to the full width | 101 inverted is 010, but 5 in 8 bits is 0000 0101, which inverts to 1111 1010. | Write all n bits first, then invert. |
| Adding 1 before inverting | The order matters: invert, then add 1. | 5 → 0000 0101 → 1111 1010 → 1111 1011. |
| Reading a negative pattern as unsigned | 1111 1011 is 251 unsigned but −5 in two’s complement. | Check the first bit before reading the value. |
| Choosing too few bits | 200 does not fit in 8 signed bits (max 127). | Use 16 bits, or the unsigned reading. |
| Extending a negative number with zeros | 1011 (−5 in 4 bits) padded to 0000 1011 becomes +11. | Sign-extend: copy the first bit — 1111 1011. |
Reference tables
FAQ
What is the range of an 8-bit two’s complement number?
−128 to 127. In general, n bits cover −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1: 4 bits −8 to 7, 16 bits −32,768 to 32,767, 32 bits −2,147,483,648 to 2,147,483,647. There is one more negative number than positive because zero takes one of the non-negative patterns.
How do you convert two’s complement to decimal?
Look at the first bit. If it is 0, read the number as ordinary binary. If it is 1, invert all the bits, add 1, and put a minus sign in front: 1111 1011 → 0000 0100 → 0000 0101 = 5 → −5. Shortcut: the first bit is worth −2ⁿ⁻¹ and the rest add normally, so −128 + 123 = −5.
What is the difference between one’s and two’s complement?
One’s complement just inverts the bits; two’s complement inverts them and adds 1. One’s complement has two zeros (0000 and 1111 in 4 bits) and a range of −7 to 7; two’s complement has a single zero and reaches −8. That single zero, and the fact that plain addition works, is why every modern computer uses two’s complement.