One's Complement Calculator

Calculate one's complement — enter your values and get an accurate result with the underlying formula.

Quick Facts

One's complement
Invert every bit (0↔1)
Flipping all bits of a binary number gives its one's complement.
Negative numbers
-x = complement of |x|
A negative value is stored as the one's complement of its magnitude's binary form.
n-bit range
-(2ⁿ⁻¹-1) to +(2ⁿ⁻¹-1)
For 8 bits: -127 to +127, with two codes for zero.

Your Results

Calculated
Binary Magnitude
-
n-bit binary of |value|
One's Complement
-
Bits inverted if value is negative
Decoded Value
-
Round-trip check back to decimal
Representable Range
-
For the chosen bit width

Ready

Enter a decimal integer and bit width, then press Calculate.

How One's Complement Works

One's complement is a way of representing signed integers in binary. Positive numbers are stored as ordinary binary, and a negative number is stored by taking the one's complement (bitwise NOT) of the binary representation of its magnitude — every 0 becomes a 1 and every 1 becomes a 0. This calculator converts a decimal integer into its n-bit one's complement pattern and decodes that pattern back to decimal so you can verify the round trip.

Formula and method

For a chosen bit width n and a value V: if V ≥ 0, write |V| as an n-bit binary number (pad with leading zeros) — that string is the one's complement representation. If V < 0, write |V| as n-bit binary, then invert every bit: representation = NOT(binary(|V|)). To decode a pattern back to decimal, check the leading (most significant) bit: if it is 0, the pattern is read as an ordinary positive binary number; if it is 1, invert all the bits, read the result as a positive binary number, and negate it. For example, with 8 bits, -18 has magnitude binary 00010010, which inverts to the one's complement value 11101101; decoding 11101101 inverts back to 00010010 = 18, so the decoded value is -18.

Common mistakes

  • Confusing one's complement with two's complement: two's complement adds 1 after inverting the bits, which removes the duplicate-zero problem below — the two systems give different bit patterns for the same negative number.
  • Choosing too few bits: a value's magnitude must fit in n-1 bits (leaving the sign position free), so an n-bit one's complement number can only hold magnitudes up to 2ⁿ⁻¹-1; larger magnitudes overflow and need a wider bit width.
  • Forgetting the two zeros: 000...0 (positive zero) and 111...1 (negative zero) both decode to the value 0 — this quirk is unique to one's complement and does not exist in two's complement.

Checking your result

A quick sanity check: the most significant bit of the one's complement pattern should be 0 for non-negative inputs and 1 for negative inputs. Inverting a one's complement pattern twice should return you to the original magnitude bits, and decoding the pattern this calculator produces should always reproduce the decimal value you entered — that round trip is shown directly in the "Decoded Value" result.

Applications

One's complement was used for signed arithmetic in some early computers (such as the CDC 6600 and UNIVAC 1100 series) before nearly all modern processors switched to two's complement. It remains actively used today in the checksum algorithm for IPv4, TCP, and UDP headers, where header words are summed using one's complement addition with an "end-around carry," and the final complement of that sum becomes the checksum field.

Frequently Asked Questions

What is one's complement in binary?
One's complement of a binary number is formed by inverting every bit (each 0 becomes 1 and each 1 becomes 0). It is used to represent negative numbers in a fixed bit width: positive numbers are stored as ordinary binary, and a negative number -x is stored as the one's complement (bitwise NOT) of the n-bit binary representation of x.
How do I convert a decimal number to its one's complement representation?
Write the number's magnitude in n-bit binary, padding with leading zeros. If the number is positive, that binary string is already the one's complement representation. If it is negative, invert every bit of that magnitude's binary. For example, with 8 bits, -18 has magnitude binary 00010010, which inverts to the one's complement value 11101101.
What is the difference between one's complement and two's complement?
Two's complement equals one's complement plus 1. One's complement has two representations of zero (00000000 and 11111111 in 8 bits), while two's complement has only one (00000000), which is why nearly all modern processors use two's complement instead of one's complement for signed integers.
Where is one's complement arithmetic used today?
Internet checksums in IPv4, TCP, and UDP headers are computed with one's complement addition, where any carry out of the most significant bit is added back into the sum (an "end-around carry"). This is a direct, still-active legacy of one's complement arithmetic from early computers such as the CDC 6600 and UNIVAC.