1's and 2's Complement Arithmetic


We can easily perform arithmetic operations using complements. We will now see addition and subtraction using 1's and 2's complement.

Subtraction using 1's Complement

There are some basic steps involved in subtracting two binary numbers using 1's complement. These are given below:

Step 1: We will take 1's complement of the subtrahend and then add it with minuend.
Step 2: If the result of the addition has any carry, then we will add that carry to the Least Significant Bit (LSB)  of the result.
Step 3: And if there is no carry bit, then we will have to take 1's complement of the result which will be a negative number.

Example with carry: Evaluate 10101 - 00111
Following the steps written above, first we will take 1's complement of 00111 (subtrahend), which will be 11000 and then add it with 10101. The result will be, 10101+11000 = 1  01101. Since we have a carry, so we will add it with the result,i.e., 01101+1 = 01110 which is the answer.

Example without carry: Evaluate 10101-10111
Following the above written steps, first we will take the 1's complement of subtrahend 10111, which will be 01000. Then we will add both of these. So, 10101+01000 = 11101. As, there is no carry bit, hence we will have to take 1's complement of the result 11101, which will be 00010, and this will be a negative number.
 

Additions by 1's Complement

Addition using 1's complement can have three possible cases. When we try to add two binary numbers, the following cases are possible:

Case 1: When one number is positive and other is negative (positive number has a greater magnitude than the negative number)
When positive number has greater magnitude, then we will take 1's complement of negative number and the end-around carry of the sum is added to the Least Significant Bit (LSB).
Example: Add 1110 and -1001
Firstly, we will take 1's complement of 1001, which will be 0110, and then we will add it with the given number,i.e., 1110+0110 = 1 0100. at last, we will just have to add this carry bit to the LSB, which will result in 0100+1 = 0101, that is the final answer.

Case 2: When one number is positive and other is negative (positive number has lesser magnitude than the negative number)  
When the negative number has a greater magnitude, then we will take 1's complement of negative number and add with the given positive number. As, here we will have no end-around carry, we will just take 1's complement of the result. the final answer will be a negative number.
Example: 1101 and -1110 
Taking 1's complement of negative number 1110, we get 0001. Now, adding 0001 with 1101, result is 1110. We will take 1's complement of 1110 ,i.e., 0001. Hence the final result is -0001.

Case 3: When we add two negative numbers.
When we add two negative number, it is quite obvious that the result will be a negative number. So in this case we will take 1's complement of  both the numbers and add both complements. We will get an end-around carry, so we will add that carry to the LSB. Now, we will take 1's complement of the result after adding the carry and this will result in the final answer.
Example: Add -1101 and -1110 in five bit register.
The five five bit numbers are, -01101 and -01110. Adding there complements, we get, 10001+10010 = 1 00011. Since, there is a carry bit 1, so add this to the LSB of the result,i.e., 00011+1 = 00100. Taking 1's complement the result we get is 11011 and it will be a negative number,i.e., -11011 is the final answer.
   

Subtraction using 2's Complement

There are some basic steps involved in subtracting two binary numbers using 2's complement. These are given below:

Step 1: We will take 2's complement of the subtrahend and then add it with minuend.
Step 2: If the result of the addition has any carry, then we will ignore that carry and the result will be a positive number.
Step 3: And if there is no carry bit, then we will take 2's complement of the result which will be a negative number.

Example with carry: Evaluate 10101 - 00111
Following the steps written above, first we will take 2's complement of 00111 (subtrahend), which will be 11001 and then add it with 10101. The result will be, 10101+11001 = 1  01110. Since we have a carry, so we will ignore it. And the final answer is 01110 which is a positive number.

Example without carry: Evaluate 10101-10111
Following the above written steps, first we will take the 2's complement of subtrahend 10111, which will be 01001. Then we will add both of these. So, 10101+01001 = 11110. As, there is no carry bit, hence we will have to take 2's complement of the result 11101, which will be 00011 and this will be a negative number.

Additions by 2's Complement

Addition using 2's complement can have three possible cases. When we try to add two binary numbers, the following cases are possible:

Case 1: When one number is positive and other is negative (positive number has a greater magnitude than the negative number)
When positive number has greater magnitude, then we will take 2's complement of negative number and the end-around carry of the sum is ignored and the result will be a positive number.
Example: Add 1101 and -1001
Firstly, we will take 2's complement of 1001, which will be 0111, and then we will add it with the given number,i.e., 1101+0111 = 1 0100. The carry will be ignored. Hence, +0100 is the final answer.

Case 2: When one number is positive and other is negative (positive number has lesser magnitude than the negative number)  
When the negative number has a greater magnitude, then we will take 2's complement of negative number and add with the given positive number. As, here we will have no end-around carry, we will just take 2's complement of the result. The final answer will be a negative number.
Example: Add 1101 and -1110 in 5-bit register. 
The 5-bit numbers are 01101 and -01110. Taking 2's complement of negative number 01110, we get 10010. Now, adding 01101 with 10010, result is 11111. We will take 2's complement of 11111 ,i.e., 00001. Hence the final result is -00001, which is the answer.

Case 3: When we add two negative numbers.
When we add two negative number, it is quite obvious that the result will be a negative number. So in this case we will take 2's complement of  both the numbers and add both complements. We will get an end-around carry, which has to be ignored. Now, we will take 2's complement of the result which will result in the final answer.
Example: Add -1101 and -1110 in five bit register.
The five five bit numbers are, 01101 and 01110. 2's complement of 01101 is 10011, and 01110 is 10010. Adding there 2's complements, we get, 10011+10010 = 1 00101. Since, there is a carry bit, so it is ignored and we will take 2's complement of the result, which will be 11011 and this number is negative,i.e., -11011.

Post a Comment

0 Comments