2’s complement

If you know what is 1’s complement, you should know 2’s complement.

The basic concept to use either 1’s complement or 2’s complement is to use it as a negative number. Subtraction operation is carried as addition of the negative number, ie, the complement of the number.

For example, 47-47=0 means 47+(-47)=0 and therefore a number X adds to its complement will become ZERO.

Now it depends on whether you are using 1’s complement as negative number or 2’s complement. Firstly we will use 1’s complement as negative number so you will see the following addition will give you:

1001+0110=1111 in binary addition

Therefore we can easily say that if “1111″ represents negative ZERO then 1001 is the 1’s complement of 0110 or negative of 0110.

To summarize the idea, say 0110 is +6 as the 4th bit is 0, 1001 is -6 as the 4th bit is 1. 0110-0110=0110+1001=1111=-0. In decimal, +6-6=+6+(-6)=-0.

Try +6-5, in binary we have 0110-0101=0110+1010(1’s complement)=10000, move the overflow bit around to have 1+0000=0001 to get the proper result of 6-5=1.

Try +6-4, in binary we have 0110-0100=0110+1011(1’s complement)=10001, add the overflow bit to have 1+0001=0010 to get the proper result of 6-4=2.

You see how the numbers are manipulated to get the result of subtration using 1’s complement.

Now we will use 2’s complement as negative number so you will see the following addition will give you:

0110+1010(2’s complement=1’s complement +1)=10000 in binary addition

Therefore we can easily say that if “10000″ is “0000″ which represents ZERO and the 5th bit is 1 and it is just the overflow. Then 1010 is called the 2’s complement of 0110 or negative of 0110.

To summarize the idea, say 0110 is +6 (positive) as the 4th bit is 0, 1010 is -6 as the 4th bit is 1. 0110-0110=0110+1010(1001+1)=10000=0. In decimal, +6-6=+6+(-6)=0.

Try +6-5, in binary we have 0110-0101=0110+(1010+1)(2’s complement)=10001, drop the overflow bit to have 1|0001=0001 to get the proper result of 6-5=1.

Try +6-4, in binary we have 0110-0100=0110+(1011+1)(2’s complement)=10010, drop the overflow bit to have 1|0010=0010 to get the proper result of 6-4=2.

You see how the numbers are manipulated to get the result of subtration using 2’s complement.

廣告