Search in shivacherukuri.tech@blogger.com

Wednesday, May 18, 2011

Wht is 2s compliment?

       Binary numbers do not have signs. So 2's complement is used to represent a negative nos. 2's complement is found in following way :

2's complement = (do 1's complement(it is to reverse the bits in a binary) +  1)
Step I)
If we have a binary no 00001100(decimal 12) then we have
to invert it by replacing all the 1s by 0 and 0s by 1.
So we get 00001100 ---> 11110011

Step II)
Now we have to add 1 to the no which we found in (I)
So we get ,
11110011 + 00000001 = 11110100


So the no 11110100 represents -12 .
As the MSB i.e. the first bit is 1 , it indicates that the no. represents a -ve no.
In binary subtraction instead of subtracting, 2's complement of a number is added.

2 comments: