In computer architecture, two binary numbers are subtracted using addition which avoids the need for a separate hardware to perform subtraction. For example, if $5-3$ is to be calculated, then the operand on the right side ($3$) will need to be converted into its negative counterpart ($-3$) and added to the other operand ($5$).
The two’s complement representation is the standard format for negative numbers.
The steps below are to be followed when subtracting $17$ from $9$:
$9 = (1001)$_{2}
$17 = (10001)$_{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 $0$s to the left of the shorter number until the sizes become equal. In our example, $9$ has four bits while $17$ has five bits, so we add one more $0$ to the left making $9 = (01001)$_{2}.
Convert $17$ into the two’s complement representation of $-17$ by inverting all of the bits and adding $1$.
When subtracting a larger number from a smaller one, we have to invert the bits of the answer and add $1$ to find the magnitude. The sign is already known to be negative.
Magnitude: $(01000)$_{2} $= 8$.
Answer: -8
RELATED TAGS
View all Courses