One's Complement Converter

Flip every bit to compute the one's-complement binary of an integer.

Ad placeholder (leaderboard)

One’s complement represents a negative number simply by inverting every bit of its positive counterpart. It is conceptually simpler than two’s complement but has a notable quirk: two distinct encodings of zero. This converter shows the exact bit pattern at common widths.

How it works

For a width of W bits:

  1. A non-negative value is written in plain binary, zero-padded to W bits.
  2. A negative value -v is the bitwise NOT of v’s binary — equivalently the unsigned pattern is (2^W - 1) - v.

Because flipping all the bits of 0 (all zeros) gives all ones, you end up with both positive zero (000…0) and negative zero (111…1). The representable range is therefore symmetric: -(2^(W-1) - 1) to 2^(W-1) - 1.

Example

Encode -42 in 8 bits. The magnitude 42 is 00101010. Invert every bit to get 11010101, which is 0xD5 and reads as 213 unsigned (equal to 255 - 42). Compare this with two’s complement, where -42 is 11010110 — they differ by exactly one because two’s complement adds a final +1.

Notes

One’s complement requires an end-around carry when adding, where a carry out of the most significant bit is added back into the least significant bit. This extra step, together with the dual-zero ambiguity, is why modern processors standardized on two’s complement instead.

Ad placeholder (rectangle)