Complement arithmetic
Complement addition
Given 1’s or 2’s complement operands, we can perform the same bit operations as we did with unsigned numbers to find the correct result. Although, at the end, we add the carry-out bit to the final result.
Subtraction
Similarly to signed-magnitude subtraction, we treat the second operand as if it was a negative number. and perform addition instead.
Overflow
Two’s complement overflow occurs when the carry-in to the most-significant bit is not equal to the carry-out.
In this case, the carry-in to the most significant bit is while the carry-out of the MSB is . Hence we’ve experienced an overflow.
In this case, the carry-in to the MSB is the same as the carry-out (). Hence, we just discard the carry-out and get the result .
Complement multiplication / division
We can take one of two approaches:
- Using a naive approach:
- Find the magnitude of both operands.
- Perform the operation as if they were unsigned.
- Convert result to negative if the operands had different signs.
- Using a specialised algorithm: Booth’s algorithm for two’s complement multiplication These are not on the exam.