One's Complement Calculator - Binary, Decimal and Hex
Enter a number in decimal, binary, or hexadecimal format, choose a bit width, and this calculator instantly returns the one's complement in all three bases. The step-by-step panel shows every conversion and bit-flip so you can follow the working. Results update as you type.
What is one's complement?
One's complement is a binary representation scheme where the negative of a number is found by flipping (inverting) every bit. For any N-bit binary number, its one's complement is computed as (2^N - 1) - x, which is equivalent to a bitwise NOT operation. For example, the 8-bit binary for 42 is 0010 1010, and its one's complement is 1101 0101 (213 unsigned). Adding any number to its one's complement always yields a string of all 1s: 0010 1010 + 1101 0101 = 1111 1111 = 255 (for 8-bit). One's complement was used in early computers such as the CDC 6600 and UNIVAC systems as a way to handle signed arithmetic, though modern hardware has largely shifted to two's complement because it avoids the double-zero problem.
How to calculate one's complement step by step
1. Write the number in binary. For decimal input, convert using repeated division by 2. For hex input, replace each hex digit with its 4-bit equivalent. 2. Pad the binary to the desired bit width (4, 8, 16, or 32 bits) by adding leading zeros. 3. Flip every bit: change each 0 to 1 and each 1 to 0. The result is the one's complement. 4. Optionally, convert back to decimal by treating the result as an unsigned binary number, or to hex by grouping bits into sets of four. Example: decimal 42 in 8-bit binary is 0010 1010. Flipping every bit gives 1101 0101, which equals 213 in decimal and D5 in hex.
One's complement vs two's complement
One's complement and two's complement are both methods for representing signed binary integers, but they differ in how they handle the most negative value and zero. One's complement has two representations for zero: all 0s (positive zero) and all 1s (negative zero). This double-zero complicates arithmetic circuits. Two's complement solves this by adding 1 to the one's complement of a number, which shifts all negative values by one and leaves only a single zero. Because of its simpler arithmetic rules and single zero, two's complement is used in virtually all modern CPUs, including x86, ARM, and RISC-V processors. One's complement remains useful in networking: the IPv4 and IPv6 checksum algorithms use one's complement addition precisely because the double-zero cancels out in practice during checksum verification.
Signed range and bit widths
The range of signed integers representable in N-bit one's complement is -(2^(N-1) - 1) to +(2^(N-1) - 1). For 8-bit: -127 to +127 (with two zeros). For 16-bit: -32767 to +32767. For 32-bit: -2147483647 to +2147483647. Compare this to two's complement, which reaches one extra negative value: -128 to +127 for 8-bit. The leading bit in one's complement acts as the sign bit (1 = negative, 0 = positive), but unlike sign-magnitude representation, the magnitude bits are also flipped rather than left unchanged. This calculator works with non-negative inputs and returns unsigned output values, which is the most common use case for one's complement in networking checksums and digital logic design.
One's complement reference table (8-bit, non-negative)
| Decimal | Binary (8-bit) | 1's Complement | Complement Decimal | Hex |
|---|---|---|---|---|
| 0 | 0000 0000 | 1111 1111 | 255 | FF |
| 1 | 0000 0001 | 1111 1110 | 254 | FE |
| 2 | 0000 0010 | 1111 1101 | 253 | FD |
| 7 | 0000 0111 | 1111 1000 | 248 | F8 |
| 10 | 0000 1010 | 1111 0101 | 245 | F5 |
| 15 | 0000 1111 | 1111 0000 | 240 | F0 |
| 42 | 0010 1010 | 1101 0101 | 213 | D5 |
| 63 | 0011 1111 | 1100 0000 | 192 | C0 |
| 100 | 0110 0100 | 1001 1011 | 155 | 9B |
| 127 | 0111 1111 | 1000 0000 | 128 | 80 |
| 128 | 1000 0000 | 0111 1111 | 127 | 7F |
| 200 | 1100 1000 | 0011 0111 | 55 | 37 |
| 254 | 1111 1110 | 0000 0001 | 1 | 01 |
| 255 | 1111 1111 | 0000 0000 | 0 | 00 |
Shows decimal, 8-bit binary, one's complement binary, and hex for common values.
Frequently asked questions
What is one's complement in binary?
One's complement is the value obtained by flipping every bit in a binary number. A 0 becomes 1 and a 1 becomes 0. For an N-bit number x, the formula is (2^N - 1) - x. The operation is also called bitwise NOT. For example, 0010 1010 (42 in decimal, 8-bit) becomes 1101 0101 (213 in decimal) after one's complement.
How do I convert a decimal number to one's complement?
First convert the decimal number to binary using the standard division-by-2 method. Then pad the result to your chosen bit width (for example 8 bits) with leading zeros. Finally, flip every bit. This calculator does all three steps automatically and also converts the result to hex.
Why does adding a number and its one's complement always give all 1s?
Because in binary, 0 + 1 = 1 and 1 + 0 = 1. Every bit position pairs a 0 from one number with a 1 from its complement, so every position sums to 1 with no carry. The result is always a string of N 1s, which equals 2^N - 1 (for example, 255 for 8-bit numbers).
What is the difference between one's and two's complement?
One's complement flips all bits. Two's complement flips all bits and then adds 1. Two's complement has a single zero and a slightly wider negative range, which is why all modern processors use it. One's complement has two zeros (all-0s and all-1s) and is mainly used today in networking checksum algorithms such as IP and TCP/UDP checksums.
How do I convert one's complement back to decimal?
If the leading bit is 0, the number is positive: simply convert the binary string to decimal using standard binary-to-decimal conversion. If the leading bit is 1, the number is negative in a signed context: flip all bits to get the magnitude, then apply a negative sign. For example, 1101 0101 has a leading 1, so flip to get 0010 1010 = 42, and the signed value is -42.
Where is one's complement actually used today?
One's complement is used in IP, TCP, and UDP checksum computation as specified in RFC 791 and RFC 793. Routers and hosts sum 16-bit words in one's complement arithmetic, which has the useful property that any carry past the most significant bit wraps around and is added back in. This makes the checksum insensitive to byte ordering. Outside networking, it also appears in some FPGA and digital logic designs.