Free · No signup · Runs in your browser
Two’s Complement Calculator
Convert a signed decimal number to two’s complement binary, or read a binary value as signed. Pick 4, 8, 16, 32 or 64 bits.
This tool needs JavaScript. Please enable it in your browser to use it.
- Instant results as you type
- Step-by-step working
- Private: input stays in your browser
- Free, no signup
To find the two’s complement of a negative number, write its positive value in binary, flip every bit, and add 1. For -5 in 8 bits: 00000101 flips to 11111010, and adding 1 gives 11111011.
How to use the two’s complement calculator
- Enter a decimal number (such as -5) or a binary string.
- Select the bit width, for example 8 bits.
- Read the two’s complement result, the signed decimal value and the valid range for that width.
Examples
| Decimal | 8-bit two’s complement |
|---|---|
| -128 | 10000000 |
| -100 | 10011100 |
| -5 | 11111011 |
| -1 | 11111111 |
| 0 | 00000000 |
| 1 | 00000001 |
| 5 | 00000101 |
| 127 | 01111111 |
Ranges by bit width
| Bits | Smallest | Largest |
|---|---|---|
| 4 | -8 | 7 |
| 8 | -128 | 127 |
| 16 | -32768 | 32767 |
| 32 | -2147483648 | 2147483647 |
| 64 | -9223372036854775808 | 9223372036854775807 |
Why two’s complement?
With the same hardware, a computer can add positive and negative numbers without special cases. The leftmost bit acts as the sign (1 means negative), and subtraction becomes addition of the complement.
Reading a negative value
If the top bit is 1, the number is negative. Flip all bits, add 1, and put a minus sign in front. For 11111011: flip to 00000100, add 1 to get 00000101, which is 5, so the value is -5. Equivalent: the unsigned value 251 minus 256.
Overflow
A number outside the range wraps around. In 8 bits, 127 + 1 becomes 10000000, which is -128. The tool warns you if the value does not fit the selected width.
Two’s complement calculator FAQ
What is the two’s complement of 0?
Zero is all zeros in every width, with no negative zero.
Why is the range not symmetric?
There is one more negative value than positive, because zero uses one of the non-negative patterns. 8 bits covers -128 to 127.
What is the difference from one’s complement?
One’s complement only flips the bits. Two’s complement flips and then adds 1, which removes the double zero.
How many bits should I use?
Use the width your problem states. 8 bits is the usual teaching example; programming types are typically 16, 32 or 64 bits.
How do I convert -1?
In any width, -1 is all ones, for example 11111111 in 8 bits.
