In this tutorial, you will learn how to find the complement in any base system. We will see complements in decimal, binary, octal, and hexadecimal number systems. Also, you will learn how computers perform signed subtraction using complements along with addition.
Contents:
- R and R-1’s Complement
- Complements in Decimal System
- Complements in Binary System
- Complements in Octal System
- Complements in Hexadecimal System
- Subtraction Using 10’s and 9’s Complements
- Subtraction Using 1’s Complement
- Subtraction Using 2’s Complement
R and R-1’s Complement
In Digital Electronics, we have the concept of complements to make certain operations like subtraction easier to perform. Complement in general means adding a feature to something. Any number system with radix R has mainly two forms of complements: – R’s Complement and (R-1)’s Complement. This is how they are found: –
- R’s Complement: For any number with Radix R and N digits, its R’s Complement is given by the formula: (RN – number)
- (R-1)’s Complement: – For any number with Radix R and N-1 digits, its R-1’s Complement is given by the formula: (RN – 1 – number)
In finding both the kind of complements, the subtraction is done as per the particular bases. Also, the interrelation between R and R-1’s Complement is
(R-1)’s Complement + 1 = R’s Complement
The addition is simpler to perform than subtraction. The advantage of using complements is that we can convert subtraction arithmetically into addition.
Complements in Decimal System
In the Decimal system, we have the base as 10. Thus we have 10 and (10-1)=9’s Complements. For any digit of Decimal, its complements are given as: –
- 10’s Complement: – 10’s Complement of any digit is 10 – that digit. For a n-bit decimal number, its 10’s complement will be (10n – number).
- 9’s Complement: – 9’s Complement of any digit is (10 –1 – that digit). For a n-bit decimal number, its 10’s complement will be (10n – 1 – number).
Here is a table that shows the unique Complements.
10’s Complement | 9’s Complement | ||
---|---|---|---|
0 | 10-0=10 | 0 | 9-0=9 |
1 | 10-1=9 | 1 | 9-1=8 |
2 | 10-2=8 | 2 | 9-2=7 |
3 | 10-3=7 | 3 | 9-3=6 |
4 | 10-4=6 | 4 | 9-4=5 |
5 | 10-5=5 |
As shown in the table, the 10’s complement and 9’s complement of a digit are given till 5 and 4 respectively as after that the complements repeat. For example, 4 is the 10’s complement of 6, and 6 is the 10’s complement of 4.
Complements in Binary
In the binary number system, we have 2 as the base. Thus Binary system has 2’s complement and 1’s complement. The complements are given as: –
- 1’s Complement: – For any n-bit binary number, its 1’s complement is found by inverting all of its digits. 1 becomes 0 and 0 becomes 1.
- 2’s Complement: – For any n-bit binary number, its 2’s complement is found by adding 1 to its 1’s complement
Here is a table that shows 1’s complement of binary digits.
1’s Complement | |
---|---|
0 | 1 |
1 | 0 |
For binary numbers, finding out the 1’s complement and 2’s complement of an n-bit number is more significant as binary has just 2 digits.
Complements in Octal
In the octal number system, we have 8 as the base. Thus, Octal has 8’s complement and 7’s complement. For Octal digits, the complement is given as; –
- 8’s Complement: – For any digit, its 8’s Complement is given by (8 – that digit).
- 7’s Complement: – For any digit, its 7’s Complement is given as (8 – 1 – that digit)
Here is a table that shows the unique Complements in Octal System.
8’s Complement | 7’s Complement | ||
---|---|---|---|
0 | 8-0=8 | 0 | 7-0=7 |
1 | 8-1=7 | 1 | 7-1=6 |
2 | 8-2=6 | 2 | 7-2=5 |
3 | 8-3=5 | 3 | 7-3=4 |
4 | 10-4=6 | 4 | 9-4=5 |
5 | 8-4=4 |
As shown in the table, the 8’s complement and 7’s complement of a digit are given till 4 and 3 respectively as after that the complements repeat. For example, 2 is the 8’s complement of 6, and 6 is the 8’s complement of 2.
Complements in Hexadecimal
In the hexadecimal number system, we have 10 as the base. Thus, Hexadecimal has 16’s complement and 15’s complement. For Hexadecimal digits, the complement is given as; –
- 16’s Complement: – For any digit, its 16’s Complement is given by (16 – that digit).
- 15s Complement: – For any digit, its 15’s Complement is given as (16 – 1 – that digit). 15 in hexadecimal is F.
Here is a table that shows the unique Complements in Octal System.
Digit | 16’s Complement | 15’s Complement |
---|---|---|
0 | 16 – 0 = 16 | 15 – 0 = 15 (F) |
1 | 16 – 1 = 15 (F) | 15 – 1 = 14 (E) |
2 | 16 – 2 = 14 (E) | 15 – 2 = 13 (D) |
3 | 16 – 3 = 13 (D) | 15 – 3 = 12 (C) |
4 | 16 – 4 = 12 (C) | 15 – 4 = 11 (B) |
5 | 16 – 5 = 11 (B) | 15 – 5 = 10 (A) |
6 | 16 – 6 = 10 (A) | 15 – 6 = 9 |
7 | 16 – 7 = 9 | 15 – 7 = 8 |
8 | 16 – 8 = 8 | 15 – 8 = 7 |
As shown in the table, the 16’s complement and 15’s complement of a digit are given till 8 and 7 respectively as after that the complements repeat. For example, 4 is the 16’s complement of 12(C) and C is the 16’s complement of 4.
Subtraction using 10’s and 9’s Complement
For subtraction of any two given signed decimal numbers, we use 9’s complement and 10’s complement to find out the value of subtraction. The steps to do so are given as: –
- Using 10’s Complement
- For two numbers A and B, if we have to subtract B from A, we find out the 10’s complement of B by subtracting it from 10N, where N is the number of digits in B.
10’s complement of B = 10N – B - We then add the 10’s complement of B to the number A and remove any carry which occurs and the remaining digits give the difference.
- Using 9’s Complement
- For two numbers A and B, if we have to subtract B from A, we find out the 9’s complement of B by subtracting it from (10N-1), where N is the number of digits in B.
9’s complement of B = 10N – 1 – B - We then add the (9’s complement of B + 1) to the number A.
- If any carry occurs, we add the carry bit to the remaining generated number, and the result that occurs is our required difference. This will give us the 10’s complement only but finding 9’s complement of a number is easier.
For example, (75)10 – (43)10, Here 75 is A and 43 is B
1st step: 10’s Complement of B is (102 – 43 = 57)
2nd step: A + 10’s complement of B = 75 + 57 = 132
3rd step: Remove the extra carry bit.
So, we get 32 as the answer.
In the same example, (75)10 – (43)10, Here 75 is A and 43 is B
1st step: 9’s Complement of B is (102 – 1 – 43 = 99 – 43 = 56)
2nd step: A + 9’s complement of B + 1 = 75 + 56 = 131.
3rd step: Add the extra carry bit to the remaining result. 31 + 1 = 32
So, we get 32 as the answer.
Subtraction Using 1’s Complement
To subtract two n-bit signed binary numbers, we can use 1’s complement method of subtraction. If we have our numbers in decimal, we can convert them into signed binary form. Here are the steps to follow to subtract two numbers A and B.
- First, the number that we have to subtract(B), we take out its 1’s Complement.
- Next, we add the 1’s complement of the number to the first number(A).
- If any carry bit is generated, we add that carry bit to the remaining digits of the result and then we get our final difference. Also, this will give us a positive difference.
- If no carry bit is generated, complement the result of step2. That will give us the result, Also, the number will be a negative difference.
For example, (0111)2 – (0110)2 , here we have A as 0111 [7 in decimal] and B as 0110 [6 in decimal]
1st step: The 1’s complement of B is 1001.
2nd step: We add 1’s complement of B to A 0111 + 1001 = 10000
3rd step: As a carry bit is generated, we add this carry bit to the remaining result
0000 + 1 =0001
Thus we have our answer as (0001) and the result obtained is +1 as we had a carry.
But if we had to subtract (0110)2 – (0111)2 , here we have A as 0110 and B as 0111.
1st step: The 1’s complement of B is 1000.
2nd step: We add 1’s complement of B to A 0110 + 1000 = 111
3rd step: As no carry bit is generated, we complement this obtained result to understand which number it is.
1110 ‘s complement —> 0001
Thus we have our answer as (1110) and we understand that the result obtained is -1 as we don’t have carry.
The disadvantage of using 1’s complement is that we need to add the carry bit.
Subtraction Using 2’s Complement
To subtract two n-bit signed binary numbers, we can also use 2’s complement method of subtraction. Here are the steps to follow to subtract two numbers A and B.
- First, we take out the 2’s complement of the number(B) that we have to subtract.
- Next, we add the 2’s complement of that number to the first number(A).
- If any carry bit is generated, we consider the difference to be positive and we ignore the carry bit from our result.
- If no carry bit is generated, we consider the difference as our result and it to be negative. We then find again the 2’s complement of the obtained result to get the equivalent signed number.
For example, (01101)2 – (01000)2, here we have A as 01101 and B as 01000
1st step: The 2’s complement of B is its 1’s complement + 1= 10111 + 1 = 11000.
2nd step: We add 2’s complement of B to A 01101 + 11000 = 100101
3rd step: As a carry bit is generated, we ignore this carry bit in our result.
Thus we have our answer as (00101) and the result obtained is positive as we had a carry.
But if we had to subtract, (01000)2 – (01101)2, here we have A as 01000 and B as 01101
1st step: The 2’s complement of B is its 1’s complement + 1= 10010 + 1 = 10011.
2nd step: We add 2’s complement of B to A 01000 + 10011 = 11011
3rd step: As no carry bit is generated, we find out the 2’s complement of this number to understand which number it is in signed form.
11011’s 2’s complement = 00100 + 1 = 00101
Thus, we have our answer as (11011) which is -5 in signed form.
Key Points to Remember
Here are the key points to remember in “Complements in Number Systems”.
- In any number system, we can have R’s complement and R-1’s complement, where R represents the radix of the system.
- We use complements exclusively to perform signed subtraction using addition.
- The R’s complement of an n-bit number can be found out by (RN– the number) and the R-1’s complement of an n-bit number can be found out by (RN -1 – the number).
- It is easier to find R-1’s complement of an n-bit number as we directly need to subtract each digit from Rn-1, which never needs a borrow.
- In the decimal number system, we have 10’s and 9’s complement and in the binary system, we have 2’s and 1’s complements.
- In the octal number system, we have 8’s and 7’s complements and in the hexadecimal number system, we have 16’s and 15’s complement.