How to subtract two binary numbers
In computer architecture, two binary numbers are subtracted using addition which avoids the need for a separate hardware to perform subtraction. For example, if is to be calculated, then the operand on the right side () will need to be converted into its negative counterpart () and added to the other operand ().
The two’s complement representation is the standard format for negative numbers.
Example
The steps below are to be followed when subtracting from :
- Convert both the numbers into binary format (the binary conversion table can be used).
2
2
-
Make sure that both of the binary numbers have the same number of bits. If they do not, the number with the lesser bits will be extended. This is done by adding extra s to the left of the shorter number until the sizes become equal. In our example, has four bits while has five bits, so we add one more to the left making 2.
-
Convert into the two’s complement representation of by inverting all of the bits and adding .
- Add and while ignoring the extra overflow bit from the answer.
When subtracting a larger number from a smaller one, we have to invert the bits of the answer and add to find the magnitude. The sign is already known to be negative.
Magnitude: 2 .
Answer: -8
Free Resources