Binary operations
Subtraction Using 1's complement
Subtraction Using 2's complement
Subtraction Using 1's complement
A simple algorithm to subtract two binary numbers - one's complement method
- Suppose a and b are the two binary numbers and we are to calculate a-b
 - Add zero's before a or b so that both have the same number of digits
 - Now add the sign bit to the left most position
 - add zero if the number is positive
 - add one if the number is negative
 - Find the one's complement of b (because b is being subtracted from a)
 - invert all the digits - all 0 become 1; all the 1 become 0.
 - You can see that the sign bit is also inverted.
 - Add 'a' and the complement of b' (a - b = a + b'). **(b' is the complement of b.)
 - check the value of end carry (the carry-over after the addition of the leftmost digit)
 - if the end carry = 1, add 1 to the result.
 - if the end carry = 0, find the complement of the result.
 
Subtraction Using 2's complement
A simple algorithm to subtract two binary numbers - two's complement method
- Suppose a and b are the two binary numbers and we are to calculate a-b
 - Add zero's before a or b so that both have the same number of digits
 - Now add the sign bit to the left most position
 - add zero if the number is positive
 - add one if the number is negative
 - Find the two's complement of b (because b is being subtracted from a)
 - invert all the digits - all 0 become 1; all the 1 become 0.
 - add 1 to this. (2's complement = 1's complement + 1)
 - You can see that the sign bit is also inverted.
 - Add 'a' and the complement of b' (a - b = a + b'). **(b' is the complement of b.)
 - check the value of end carry (the carry-over after the addition of the leftmost digit)
 - if the end carry = 1, the result you've obtained is your expected result.
 - if the end carry = 0, find the 2's complement of the result to get your expected result.
 
Comments
Post a Comment