What are 1's Complement and 2's Complement ?
1’S COMPLEMENT AND 2’S COMPLEMENT
1’s complement and 2’s complement are the most fundamental
topics to know about the working function of computers. To understand these, you
must have a basic knowledge of binary number system. So I am assuming that you
understand the idea of addition and substitution in binary number system. If
you do not know the basic I have already described the basic of binary number system.Go to that article and then come back.
Before entering into the topic let us understand what the
word “complement” stands for. It simply
means “the rest portion without that”. For example , if you have a set of 0 to
100 numbers ( say U ) and an another set containing of 0 to 20 numbers ( say A
) then the complement of A in U will be the “rest portion without that” i.e.
the remaining set containing 21 to 100 numbers. Same concept works here. In 8–bit word* the maximum number it can contain
is 1111 1111.So the 2’s complement of 1011 1011 for 8-bit word will be equal to 1’s complement of that number
+ 1 ̵̵̵̵ ̵̵ ̵ ̵
0 1 0 0 0 1 0 0
( 1’s complement of 1011 1011 )
+ 1
̅0̅ ̅1̅ ̅0̅ ̅0̅ ̅0̅ ̅1̅ ̅0̅ ̅1̅
Do you get it? Surely not!! Okay don’t worry! I will come back
later. For now, let’s check whether the result is really the complement of 1011
1011 or not. For that I am subtracting 1011 1011 from the number 1 0000 0000 ̵ ̵ ̵ ̵ ̵
1 0 0 0 0 0 0 0 0
- 1 0 1
1 1 0 1 1
̅ ̅0̅ ̅1̅ ̅0̅ ̅0̅ ̅ ̅0̅ ̅1̅ ̅0̅ ̅1̅ ̅
As you can see two results are same .So the above result is
correct.
Because we are familiar with decimal numbers so we will
understand binary complements with the help of decimal complements( 9’s
complement and 10’s complement ). After that you will be able to understand
binary complements easily.
9’S COMPLEMENT
It is similar to 1’s complement. Decimal number system has
10 digits( 0 to 9 ). So, the maximum number, the two-digit decimal number
system can contain is 99.In this case, complement of 23 will be –
99
- 23
̅ ̅7̅6̅ ̅ ̅
This number is called 9’s complement of 23 in a two-digit
number system. Similarly, for single digit number the 9’s complement of 3 will be 9 – 3 = 6.
10’S COMPLEMENT
It is similar to 2’s complement. For single-digit number the 10’s complement of 3
will be 10 – 3 = 7. For two-digit number
10’s complement of 23 will be 100 – 23 = 77.
If you see 9’s complement and 10’s complement very carefully
you can find a relation between them.
We can get 10’s complement of a number by finding 9’s
complement of that number and then adding 1 to it.
So 10’s complement of 23 is equal to 9’s complement of 23 +
1 that is 76 +1 =77.
Finally we can move to our topic.
1’s COMPLEMENT
As you know binary number system has only two digits (0 and
1 ),the maximum number of two-bit number is 11.If we add 1 to 11 we get 100.
In that case the 1’s complement of 01 will be 11 – 01 =10 .
1’s complement of 1011 will be 1111 – 1011= 0100.
Do you find an another method to find 1’s complement? See
carefully. You will discover that one can get 1’s complement of a number by
replacing the digits of that number by their counter digits that is replacing 0s
with 1 and vice-versa.
So , 1’s complement of 1011 will be 0100 .
2’S COMPLEMENT
You guess it right? 2’s complement of 01 will be 100 – 01 =
11.Similarly 2’s complement of 1011 will be 10000 – 1011 = 0101.
Like 10’s complement ,2’s complement also can be found by
finding 1’s complement and then adding 1 to it.
There is another method to find the 2’s complement –
- Start at the least significant bit of the given number and then check the bits to left.Keep all the bits same up to and including the least significant 1 .
- Then replace all 1s with 0 and vice-versa.
For example, 2’s complement of 0010 0000 is 1110 0000.
I just grabbed the number. Then started to see all the bits
from right to left until I have found the least significant 1 ,write it as they
are including least significant 1 and after that I replaced every 0 with 1 and
vice-versa.
Hope,you have no doubt on 1’s complement and 2’s complement.
Now you can go to the first case and you will understand the case easily.
WHAT ARE THE USES OF 1’S COMPLEMENT AND 2’S COMPLEMENT ?
Well, microprocessor uses 1’s complement and 2’s complement
for subtraction .There is a wonderful thing about 2’s complement. 2’s
complement of a number is equal to the negation of that number.for
example,binary representation of 32 is 0010 0000 ,then 2’s complement of 0010
0000 is 1101 1111 + 1=1110 0000 which is equal to -32. I will cover this in
next article.
Comments
Post a Comment
If you have any doubt please comment and let me know