One's complement

Format

Sign-magnitude is conceptually simple, but messy to implement in hardware. For this reason, other possibilities were explored, including one's complement.

Positive values in one's complement are the same as unsigned binary or sign-magnitude.

Negation

To negate a one's complement value, we invert all bits. Like sign-magnitude, one's complement has two representations for zero, e.g. +0 = 00000000 and -0 = 11111111.

Caution

The term "one's complement" can refer to the binary format (representation) or the negative of a one's complement binary value (the one's complement of 1011 is 0101, and negating is sometimes called "taking the one's complement"). Watch out for this and use the context of the sentence to understand which one we're talking about.

I've often wondered if people who create this kind of confusion are just evil, and intent on making students suffer. However, we should never ascribe to malice what can be explained by incompetence.

In this text, if we want you to negate a value, we will say negate the value. The term "one's complement" refers to the binary number system.

A more universal term for a value with all bits inverted is simply the complement. The complement of a binary value N is sometimes called "N prime" and is written as N'. For example, 00110101' = 11001010 and 11001010' = 00110101.

Conversions

What are the decimal values of the following 8-bit one's complement numbers? If the number is positive, which is indicated by a 0 in the leftmost bit, we just treat it like an unsigned integer. If the leftmost bit is 1, indicating a negative value, we invert it, convert the positive (unsigned) value, and add a '-' sign.

• 00001010 = +(8 + 2) = +10
• 10001010 = -(01110101) = -(1+4+16+32+64) = -117

Addition and subtraction work like unsigned for positive numbers. If negative numbers are involved, arithmetic is slightly complicated. One's complement is not generally used in hardware implementations for this reason.

Range

Range of an N-bit one's complement system is the same as N-bit sign-magnitude, +/-2N-1-1.

Comparison

Comparison works like unsigned if both values have the same sign. If the signs differ, the positive number is greater.

Note

Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
1. Perform the following conversions.

1. 11111111 8-bit one's comp to decimal

2. 01111111 8-bit one's comp to decimal

3. -7 decimal to 8-bit one's comp