Intuitive view to 1s and 2s complement system

explanation math algo

Why so complicated

The binary system makes it simple to represent integer values. But when it comes to negative values (and having the same representation for positive integers), there is no one intuitive way.

The most clear cut method would probably be to add another bit to distinguish the sign. Usually the most significant bit (MSB), so as to ensure that positive integers are represented in the same manner.

This sign-and-magntude method has its flaws, the major one being the inability to operate binary addition efficiently. As such, two other systems were introduced instead - the 1s and 2s complement system.

The main idea behind the system was to facilitate binary addition such that you could perform binary addition on the two different values and get the right answer for your problems.

How the system works

The complement system

This post is not really about the complement system itself, but I have found a pretty good explanation for how you find the value of such a complement system.

A few things to note about the difference between the complement 1s and complement 2s system. The only difference is that in 1s representation, there is 2 values for 0 - 0000 and 1111 (for 4 bit numbers).

Binary Addition using the sytem

There are many resources to figure out how you do binary addition under the 1s and 2s complement system.

This post is not about to explain the mechanics behind the addition, but rather, aims to explains the carry over step that you do at the very end of the addition for both systems.

And the magic behind it

Now that you kind of know how it works, you will probably still be a little amazed and confused at the same time? How did they know that this works? What is this sorcery?

Well, that went through my mind the first time I learnt the complement system too. Then I found this really really amazing explanation based on the idea of a number line, and that was where everything fell into place.

2s complement system (1s later)

Imagine a number line of positive integers, from 0 to 7, (000 to 111 in binary). Then extend the value to negative values. Now you have a proper number line to work with.

And what does proper means? You have do addition as per normal. And on a number line, this is represented by moving to the right. And we gonna do 2s complement first, and it has a range of -8 to 7

And what about the complements system that we describe before? The positive number have to worked as they used to. Hence, we will have to place in the values for those values first.

number line with binary values from 0 to 7

Then what about those other values? Simple, but brilliant at the same time (you will see why later). We just have to duplicate the whole number line over at the end. (the part highlighted green)

And of course, the values of the values will thus be determined using the red range, half from yellow, half from green.

The full thing

Binary addition using 2s complement system

Addition on a number line is to move to the values on the right. And from the number line, you can see that there is 3 main ways of moving to the right.

  1. Region of negative values to negative values
  2. Region of negative values to positive values
  3. Region of positive values to positive values

ways to do binary addition

Ordinary binary addition takes care of case 1 and 3. But for case 2, we have to take a deeper look at the “carry over” step of doing binary addition on 2s complement system.

working for -1 plus 2 equals 1 in 2s

The carry over step for binary addition on the number line for the 2s complement system require only the dropping of the additional MSB (most significant bit).

From the diagram above, it is easy to see why this works. Dropping the additional bit in the front returns you the same representation for your positive values.

1s complement system

The binary addition process for the 1s complement system is slightly more troublesome. The carry over process actually requires you to add 1 to the final value.

working for 1s

If you refer to the number line for the 1s complement system, you can easily see why this is the case. Similar to the previous number line, dropping the most significant bit gives you the value.

number line for 1s

However, the different lies in the fact that the 1s complement system has 2 values for 0 - 0000 and 1111 (for 4 bit numbers). So essentially, when there is a “carry over”, the value 0 is double counted.

To fix this double counting, we simply add 1 to the final value.

end

This intuitive view on the 1s and 2s complement system helped provide a satisfactory explanation as to why the number system worked this way.