One's Complement

Learn how one’s complement solves the issues related to operations on negative numbers.

Disadvantages of SMR

SMR has two disadvantages. It led to technical issues when computer engineers used this representation in practice. So, engineers started looking for an alternative approach to store numbers in memory. This way, they came to one’s complement representation.

The first problem of SMR is related to operations on negative numbers. The one’s complement solves it. Let’s consider this problem in detail.

The example will explain to us what exactly happens when we operate on negative numbers in SMR. Let’s suppose that we want to add integers 10 and -5. First, we should write them in SMR. We assume that each integer occupies one byte in computer memory. Then, we represent them like this:

10 = 0000 1010
-5 = 1000 0101

Now, the question arises: How does the processor add these two numbers? Any modern processor has a standard module called the adder. It adds two numbers in a bitwise manner. If we apply it for our task, we get the following result:

10 + (-5) = 0000 1010 + 1000 0101 = 1000 1111 = -15

This result is wrong. This means that the adder cannot add numbers in SMR. The calculation mistake happens because the adder handles the highest bit of the number incorrectly. This bit stores the integer’s sign.

There are two ways to solve this problem:

  1. Add a special module to the processor. It should process operations on negative integers.

  2. Change the integer representation in memory. The representation should fit the adder logic when it operates on negative integers.

The development of computer technology decided on the second way. This is because it is cheaper than complicating the processor architecture.

One’s complement

The one’s complement may remind us of SMR. The sign of the integer occupies the highest bit. The remaining bits store the number. The difference from SMR is that all bits of a negative number are inverted in one’s complement. This means zeros become ones, and ones become zeros. Bits of positive numbers are not inverted.

The following table shows the one’s complement representation of some numbers.

Decimal Hexadecimal One’s Complement
-127 80 1000 0000
-110 91 1001 0001
-60 C3 1100 0011
-5 FA 1111 1010
-0 FF 1111 1111
0 0 0000 0000
5 5 0000 0101
60 3C 0011 1100
110 6E 0110 1110
127 7F 0111 1111

Get hands-on with 1200+ tech skills courses.