Developer Binary

Two's complement calculator

Decimal value
Bit width
Binary 11010110
-42 in 8 bits
Hexadecimal D6
As unsigned 214
As signed -42
Range at this width −128 … 127
Fits? yes
8 bits: −128 to 127

To negate a number in two’s complement, flip every bit and add one. 42 is 00101010, inverted is 11010101, plus one gives 11010110 — which is −42. The reason this works is that it makes addition identical for signed and unsigned values, so a processor needs only one adder circuit rather than two. That single design economy is why two’s complement won over the alternatives.

Advertisement
320 × 100

Two's complement represents negatives by flipping every bit and adding one. In 8 bits, −42 is 11010110, which reads as 214 unsigned. The signed range for 8 bits is −128 to 127.

How to read two's complement

1 Enter a decimal value, positive or negative.
2 Choose the bit width.
3 Read the binary and hexadecimal representation.
4 Check the range row — values outside it wrap around silently.

The asymmetry of the range trips people up: 8 bits hold −128 to 127, one more negative than positive. That is because zero takes up a slot on the positive side, and it means negating the most negative value overflows — the negative of −128 in 8 bits is still −128. It is a genuine edge case that has caused real bugs, most famously in code that takes the absolute value of an integer without checking for it.

Questions

Invert every bit of the positive value and add one.

Advertisement
300 × 250
Was this tool any good?
INTERNAL SIGNAL ONLY · WE USE IT TO FIND TOOLS WORTH REBUILDING