Two's Complement Calculator
Convert between signed decimal values and their binary representation.
What the Two's Complement Calculator does
Two’s complement represents negative numbers by inverting the bits of the magnitude and adding one. The top bit then acts as a sign flag, and ordinary binary addition gives correct results for both signs — which is why virtually every processor uses it.
Formula
Negative value = ~magnitude + 1Signed value = unsigned − 2ⁿ when the sign bit is setSigned range = −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1Unsigned range = 0 to 2ⁿ − 1
Inputs explained
| Input | Unit | Required | Notes |
|---|---|---|---|
| Start from | one of 2 options | Yes | — |
| Decimal value | text | In some modes | Shown Start from is A decimal value. |
| Bit pattern | text | In some modes | Shown Start from is A binary or hex bit pattern. |
| Pattern is in | one of 2 options | In some modes | Shown Start from is A binary or hex bit pattern. |
| Bit width | one of 4 options | Yes | — |
How to use it
- Choose Start from and Bit width.
- Fill in the remaining inputs the form shows for your choice.
- Select Calculate.
Worked example
Representing −5 in 8 bits.
- Value
- −5
- Bit width
- 8-bit
5 is 00000101. Inverting gives 11111010, and adding 1 gives 11111011 — 0xFB, which reads as 251 unsigned.
Frequently asked questions
Why is the signed range asymmetric?
Zero takes one of the 2ⁿ patterns from the positive side, leaving one fewer positive value than negative. An 8-bit signed integer spans −128 to 127.
What happens on overflow?
The value wraps around. Adding 1 to 127 in 8-bit signed gives −128, because the bit pattern rolls from 01111111 to 10000000.