Hex Two's Complement Calculator
Flip the sign of a hex value at a chosen bit width using two's complement — the encoding almost every modern system uses to represent negative integers.
Full breakdown (result at 8-bit)
How to Calculate Two's Complement
Two's complement flips a value's sign within a fixed bit width: invert every bit (change every 0 to 1 and every 1 to 0), then add 1 to the result. This is the encoding almost every modern processor uses to represent negative integers.
Running the process on a positive value produces its negative encoding; running it again on that result produces the original positive value back — the operation is its own inverse.
Two's Complement Example, Step by Step
05 (8-bit) -> FB
Two's complement of 0x05 at 8-bit = 0xFB
05 = 0000 0101 Invert: 1111 1010 +1: 1111 1011 = FB
| Step | Description | Result |
|---|---|---|
| Invert all bits | 0000 0101 inverted is 1111 1010 | FA |
| Add 1 | FA + 1 = FB | FB |
| Check the result | FB, read as signed 8-bit, is -5 | -5 |
An edge case worth knowing: applying this same process to 0x80 (the most negative 8-bit value) produces 0x80 again, since -128 has no positive counterpart at that width.
Common Mistakes With Two's Complement
- Stopping after inverting the bits and forgetting to add 1 — that's one's complement, not two's.
- Adding 1 before inverting instead of after.
- Applying the process at the wrong bit width, changing which bits actually get inverted.
- Expecting the most negative value at a given width to have a positive counterpart when it doesn't.
Frequently Asked Questions
What does two's complement actually do?
It flips a value's sign within a fixed bit width: invert every bit, then add 1. Applying it to a positive bit pattern gives you the negative encoding of the same magnitude, and applying it again gives you back the original.
Why invert the bits and add 1, instead of just inverting?
Inverting alone (one's complement) has two representations of zero, which causes problems in hardware arithmetic. Adding 1 collapses that to a single zero and makes addition/subtraction circuits work identically for positive and negative numbers.
What happens when I take the two's complement of the most negative value?
You get the same bit pattern back. 0x80 (-128 at 8-bit) has no positive counterpart at that width, so inverting and adding 1 wraps around to 0x80 again — this is a well-known edge case in signed arithmetic.
Is two's complement the same as just interpreting a hex value as negative?
No — reading an existing bit pattern's sign is what the Hex to Negative Decimal converter does. Two's complement instead transforms a bit pattern into its negated version, producing a new value.
How is two's complement different from one's complement?
One's complement is just the bit inversion — stop there and it has two representations of zero. Two's complement adds 1 after inverting, which is what modern hardware actually uses.
Why does bit width matter here?
Inverting bits only makes sense across a specific count of them — the same hex value produces a different two's-complement result at 8-bit than it does at 32-bit, since more leading bits get flipped.