259 views
2 votes
2 votes
how to detect overflow when subtracting two 2's complement number?

2 Answers

1 votes
1 votes

First note that, when you are subtracting two signed numbers (assuming that the numbers are represented in their 2’s complement form), then an overflow can occur if the signs of both the numbers (i.e., the minuend and the subtrahend) are different, because then the result would fall outside the representable range (but, this is not the only condition that needs to be satisfied).

The other condition – If the sign of the result of the subtraction operation is same as the sign of the subtrahend, then it indicates an overflow.

See: Hamacher, Computer Organization and Embedded Systems (6th Ed., pg-15)

Also see: https://www.doc.ic.ac.uk/~eedwards/compsys/arithmetic/index.html

edited by
0 votes
0 votes
I don't think so that subtraction can cause to overflow! Overflow happens when either both numbers are +ve or -ve.
If one number is +ve and other is -ve, overflow never happens.

No related questions found