Hex One's Complement Calculator
Invert every bit of a hex value at a chosen bit width — one's complement, the sign-flip encoding that two's complement later replaced.
Full breakdown (result at 8-bit)
How to Calculate One's Complement
One's complement is the simpler of the two complement encodings: invert every bit of the value at a fixed bit width — every 0 becomes 1, every 1 becomes 0 — and that's the whole process, no addition involved.
It predates two's complement as a way to represent negative numbers, but fell out of use for that purpose because it has two bit patterns that both mean zero (all bits 0, and all bits 1), which complicates hardware comparisons and arithmetic.
One's Complement Example, Step by Step
05 (8-bit) -> FA
One's complement of 0x05 at 8-bit = 0xFA
05 = 0000 0101 Invert every bit: 1111 1010 = FA
| Step | Description | Result |
|---|---|---|
| Invert all bits | 0000 0101 inverted is 1111 1010 | FA |
Compare this to two's complement of the same value (FB, one more) — the difference between the two encodings is exactly that final +1 step.
Where One's Complement Actually Shows Up
Computing an Internet Checksum
IPv4, TCP, and UDP headers are all validated with a one's-complement checksum — if you're hand-verifying a packet capture, this is the exact bit-inversion step that checksum relies on.
~0x1234 (16-bit) = 0xEDCB
Implementing a Bitwise NOT
Any time code applies a bitwise NOT (~) to a fixed-width value, that operation is one's complement — useful for building masks or flipping a set of flags all at once.
~0x0F (8-bit) = 0xF0
Studying Legacy Computer Architectures
Some early computers (like the CDC 6600) used one's complement for signed integers directly — understanding it helps make sense of why those systems had two representations of zero.
~0x80 (8-bit) = 0x7F
Common Mistakes With One's Complement
- Adding 1 after inverting, which turns it into two's complement instead.
- Forgetting that one's complement has two zero representations, which can cause confusing comparison results.
- Applying it at the wrong bit width, changing which bits actually get inverted.
- Assuming it's still the standard for signed integers in modern software — it isn't; two's complement is.
Why Use This Calculator Instead of Doing It by Hand
- Inverts every bit at your chosen width instantly, no manual bit-flipping
- Runs entirely in your browser — nothing you type gets sent anywhere
- Shows decimal, binary, and octal for the result at once
- Lets you switch bit widths to compare how the same value inverts at each
Frequently Asked Questions
What is one's complement?
Simply inverting every bit of a value at a fixed bit width — every 0 becomes 1 and every 1 becomes 0. It's the first half of two's complement, without the final add-1 step.
Why isn't one's complement used in modern computers?
It has two representations of zero (all-0s and all-1s), which complicates arithmetic circuits and comparisons. Two's complement fixes this by adding 1 after inverting, leaving a single, unambiguous zero.
Where is one's complement still used today?
In some checksum algorithms — the Internet checksum used in IPv4, TCP, and UDP headers is computed using one's-complement addition, which is a different reason to encounter it than representing negative integers.
How is one's complement different from two's complement here?
One's complement just inverts the bits. Two's complement inverts the bits and then adds 1 — that extra step is what makes two's complement the encoding modern processors actually use for signed integers.
Does inverting a value twice give back the original?
Yes — one's complement is its own inverse. Inverting a bit pattern and then inverting the result again always returns the original value.
How do I interpret a one's-complement result as a negative number?
Check the leftmost bit at your bit width — if it's set, the value is negative, and its magnitude is found by inverting the bits again (back to the original) rather than the invert-then-add-1 process two's complement uses.
How is a one's complement calculator different from a NOT operation?
They're the same operation — one's complement is exactly a bitwise NOT applied at a fixed width. "One's complement" is the math/networking term for it; "NOT" or "~" is the name you'd see in code.
Why does the Internet checksum use one's complement instead of two's complement?
One's-complement addition wraps its carry-out back into the low bit (an "end-around carry"), which makes the checksum symmetric and easy to verify by summing everything including the checksum itself and checking for all-1s — a property two's complement doesn't have.