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.