What Is One's Complement?
One's complement, also written as 1's complement or ones' complement, is a binary operation that changes every zero to a one and every one to a zero. It is also a historical method for representing positive and negative integers in digital systems.
For example, the 8-bit binary number 00000101 represents
positive five. Flipping all eight bits gives
11111010, which represents negative five in an
8-bit one's-complement system.
How to Calculate One's Complement
- Choose the number of bits, such as 8 or 16.
- Write the input as a binary pattern with the chosen width.
- Replace every 0 with 1 and every 1 with 0.
- Read the resulting pattern or interpret it as a signed value.
01010101 → 10101010
11110000 → 00001111
One's-Complement Decimal Conversion
For a positive integer, the one's-complement representation is its ordinary binary form padded to the selected width, with a zero as the most significant bit. For a negative integer, first convert its absolute value to binary and then invert every bit.
In an 8-bit system, positive five is
00000101. Negative five is formed by inverting those bits:
11111010. To decode that negative pattern, invert it again
to get 00000101, whose magnitude is five, and apply the
negative sign.
One's-Complement Examples
| Decimal input | 8-bit binary | One's-complement encoding |
|---|---|---|
| +5 | 00000101 |
00000101 |
| -5 | 00000101 (magnitude) |
11111010 |
| +42 | 00101010 |
00101010 |
| -42 | 00101010 (magnitude) |
11010101 |
| +0 | 00000000 |
00000000 |
| -0 | 00000000 (magnitude) |
11111111 |
Understanding the Sign Bit
In one's-complement signed representation, the most significant bit indicates the sign. A leading zero indicates a non-negative value. A leading one indicates a negative value, including the special negative-zero pattern consisting entirely of ones.
For an n-bit value, the signed range is
-(2^(n-1)-1) through
+(2^(n-1)-1). For example, an 8-bit one's-complement
integer ranges from -127 to +127. There is no representation for -128
in an 8-bit one's-complement system.
One's Complement vs. Two's Complement
| Feature | One's complement | Two's complement |
|---|---|---|
| Negative encoding | Invert all bits | Invert all bits and add one |
| Zero | Positive zero and negative zero | One zero representation |
| 8-bit signed range | -127 to +127 | -128 to +127 |
| Modern use | Historical representation; also relevant to one's-complement arithmetic and checksums | Common signed integer representation in modern processors |
One's-complement arithmetic is also important in checksum calculations. In one's-complement addition, any carry beyond the most significant bit is wrapped around and added to the low-order bits. This is distinct from simply flipping bits and is why one's complement and two's complement should not be treated as interchangeable.