Computing Library › Number Systems & Information
Number Systems & Information

One's Complement

One's complement represents a negative number by inverting all the bits of its positive form.

The scheme

In one's complement, negating a number means flipping every bit. The 8-bit value 5 is 00000101, so −5 is 11111010. The top bit still indicates the sign, and positive values look identical to their unsigned form.

Two zeros

Kronos motion — number counters

This representation has a drawback: both 00000000 and 11111111 mean zero, called positive and negative zero. Having two zeros complicates comparisons and equality checks.

End-around carry

Addition in one's complement requires a correction: any carry out of the top bit must be added back into the least significant bit. This extra step is why two's complement, which needs no such fix, replaced it.

Where it survives

One's complement arithmetic lives on in the Internet checksum used by IP, TCP, and UDP, where its end-around carry gives useful properties for detecting errors across 16-bit words.

Comparison with two's complement

Both use the top bit as a sign, but two's complement adds 1 during negation, eliminating the second zero and the end-around carry. That single difference makes two's complement simpler in hardware.

python
def ones_comp_neg(x, n):
    return (~x) & ((1 << n) - 1)
print(bin(ones_comp_neg(5, 8)))  # 0b11111010