Skip to main content

Subtraction of two binary numbers using 1's complement and 2's complement

In this tutorial, we will learn how to compute the difference between two binary numbers using 1's complement and 2's complement. 
Let us consider two binary numbers $X$ and $Y$. 
We want to compute $X - Y$ here. 

Method 1: Using 1's complement 
Step 1: Find 1's complement of $Y$. 
Step 2: Add $X$ and $Y$. 
Step 3: If there is a carry, then add this carry to the answer. If there is no carry, then find the 1's complement of the answer and place a negative sign in front of the answer. 

Example 1: Compute $(101)_2 - (011)_2$ using 1's complement method.  
Solution: 
Here, $X = (101)_2$ and $Y = (011)_2$. 
Step 1: 1's complement of $Y$ is $(100)_2$. 
Step 2: $X + Y = (101)_2 + (100)_2 = (1 001)_2$. 
Step 3: There is a carry of 1, so now we will add this carry to the answer. 
Therefore, the final result is $(1)_2 + (001)_2 = (010)_2$. 
Example 2: Compute $(011)_2 - (101)_2$ using 1's complement method. 
Solution: 
Here, $X = (011)_2$ and $(101)_2$. 
Step 1: 1's complement of $Y$ is $(010)_2$. 
Step 2: $X + Y = (011)_2 + (010)_2 = (0 101)_2$. 
Step 3: There is no carry. So, we will compute the 1's complement of $(101)_2$, which is $(010)_2$. 
Therefore, the final result is $-(010)_2$. 

Method 2: Using 2's complement 
Step 1: Find 2's complement of $Y$. 
Step 2: Add $X$ and $Y$. 
Step 3: If there is a carry, then discard this carry and return the sum as the answer. If there is no carry, then find the 2's complement of the answer and place a negative sign in front of the answer. 

Example 3: Compute $(101)_2 - (011)_2$ using 2's complement method.  
Solution: 
Here, $X = (101)_2$ and $Y = (011)_2$. 
Step 1: 2's complement of $Y$ is $(101)_2$. 
Step 2: $X + Y = (101)_2 + (101)_2 = (1 010)_2$. 
Step 3: There is a carry of 1, so now we will discard this carry and return the sum as the answer. 
Therefore, the final result is $(010)_2$. 
Example 4: Compute $(011)_2 - (101)_2$ using 1's complement method. 
Solution: 
Here, $X = (011)_2$ and $(101)_2$. 
Step 1: 2's complement of $Y$ is $(011)_2$. 
Step 2: $X + Y = (011)_2 + (011)_2 = (0 110)_2$. 
Step 3: There is no carry. So, we will compute the 2's complement of $(110)_2$, which is $(010)_2$. 
Therefore, the final result is $-(010)_2$. 


Comments