When we hear about negative numbers the symbol " - " comes to mind since the use of the symbol seems to make any number negative.

As human beings it is pretty easy to think about negative numbers and deal with the " - " symbol. But for a computer we need a binary notation for this too since there is no way of representing " - ", it either has to be a 0 or 1. In this post I will try and show the various ways one could write negative numbers in binary and whether or not they are suitable for doing mathematics.
To test if the representation method is appropriate we can try doing a simple arithmetic operation such as subtraction. If the result generated after the operation matches the correct result, we can be sure that the system of representing the numbers works.
To test if the representation method is appropriate we can try doing a simple arithmetic operation such as subtraction. If the result generated after the operation matches the correct result, we can be sure that the system of representing the numbers works.
Sign Magnitude:
To solve the problem of handling negative numbers we can device a simple solution of using an extra bit on the left of the number and call it the "Sign Bit". The rest of the bits on the right will denote the magnitude or the actual number.
Using this method we get the following table:
In this method however, we notice a problem. As highlighted in the table, there are two notations of the number zero +0 and -0.
Now, let's try doing some simple arithmetic operation with it.
Suppose we had to do the following operation:
7 - 3 = ?
to do that we could try and use this negative number notation, turning the problem into:
7 + (-3) = ?
Now, adding the two numbers in binary we get:
As you can see the answer is incorrect since it should be 0100 (+4). Hence, this is not an appropriate method to represent negative numbers.
1's Complement:
In this method the positive numbers are written as it is while having an extra zero digit on the left. this extra digit is considered the sign bit.
To represent negative numbers the same positive numbers are inverted i.e. turn all 1's to 0's and vice versa. By this method the following table can be made:

In this method however, we notice the same problem. As highlighted in the table, there are two notations of the number zero +0 and -0.
But let us ignore this fact for now and try doing some simple arithmetic with it.
Let's try the previous operation again:
7 + (-3) = ?
Now, adding the two numbers in binary we get:
In this case the generate carry is added to the number again giving us the correct answer 0100 (+4). So even though this system still has two representations of zero its still allows operations to function correctly.
2's Complement:
This method of representing negative numbers is similar to 1's complement. The only difference being - after inverting the bits, i.e. turning 1's to 0's and vice versa, 1 is added to the number and any carry generated is discarded. Applying 2's complement to the numbers gives us the following table:
The first thing one might notice is that there is only one representation for zero i.e. 2's complement of 0000 is 0000.
Now, let's try doing the previous operation again using 2's complement:
7 + (-3) = ?
In this case the carry generated is discarded. As can be seen from this example the 2's complement method of writing negative numbers gives us the correct answer 0100 (+4).
So, the 2's complement method not only eliminates the extra zero but also gives us the correct result.
This concept of bit inversion and adding 1 can actually be used to modify the adding machine from the previous post to a subtracting machine as well (give it a try maybe??).
This concept of bit inversion and adding 1 can actually be used to modify the adding machine from the previous post to a subtracting machine as well (give it a try maybe??).
Got any queries???
E-Mail me at: shashwath.sundar@gmail.com
Comments
Post a Comment