Is the following a valid alternative definition of overflow in twos complement arithmetic?
If the exclusive-OR of the carry bits into and out of the leftmost column is 1, then
there is an overflow condition. Otherwise, there is not.
-
The overflow rule was stated as follows: If two numbers are added, and they are
both positive or both negative, then overflow occurs if and only if the result has
the opposite sign.
There are four cases:
•Both numbers positive (sign bit = 0) and no carry into the leftmost bit position:
There is no carry out of the leftmost bit position, so the XOR is 0. The result has a
sign bit = 0, so there is no overflow.
•Both numbers positive and a carry into the leftmost bit position: There is no carry
out of the leftmost position, so the XOR is 1. The result has a sign bit = 1, so there
is overflow.
•Both numbers negative and no carry into the leftmost position: There is a carry
out of the leftmost position, so the XOR is 1. The result has a sign bit of 0, so there
is overflow.
•Both numbers negative and a carry into the leftmost position. There is a carry out
of the leftmost position, so the XOR is 0. The result has a sign bit of 1, so there is
no overflow.
Therefore, the XOR result always agrees with the presence or absence of overflow.
0 comments:
Feel free to contact the admin for any suggestions and help.