You are on page 1of 2

CS 1104 Discussion Forum Unit 3

What happens when the signs of the numbers are the same?

There are simple rules for identifying overflow in a two's complement sum. If the result is
negative, the total of the two positive values has overflowed. If the result is positive, the total of
the two negative values has overflowed. There hasn't been any additional spillage of the amount.
It’s critical to understand that carry out and overflow can both occur simultaneously. Carry out
and overflow in unsigned numbers are the same. Nothing concerning overflow in two's
complement is revealed by carry out. The limits are there because overflow in two's complement
occurs when one is added rather than when a bit is taken out of the left column (Bennet, n.d.).

Overflow cases for same signs:


-(+A) + (+B) = −C
-(−A) + (−B) = +C
If we add 2 negative numbers, we will have to follow certain steps:

We must first convert it to the complement of two. The addition must then be done. The MSB
value will be 1, denoting a negative number. The magnitude bits will then be taken once that
MSB is excluded. The number is once more converted to 2's complement before being assessed
as a decimal number with a negative sign. As a result, combining two negative binary numbers
also produces a negative number.

What happens in the case of subtraction?

When two Two's Complement numbers are subtracted, overflow occurs if and only if the result
has the same sign as the subtrahend (Edwards, 2002)

Overflow cases for subtraction:


-(+A) − (−B) = −C
-(−A) − (+B) = +C

How do we detect when an overflow does occur?

When two integers are added and the result is outside the range allowed by the binary
representation being used, this is known as an arithmetic overflow error (Tarnoff, 2005-2007,
p.67).If the outcome is not inside the boundaries of the binary representation (Tarnoff, 2005-
2007, p.67).Overflow has happened if we add two positive values and the result is negative.
Overflow occurs if we add two negative numbers and the result is positive (Tarnoff, 2005-2007,
p.68).

References
Bennet. (n.d.). Two's Complement Overflow Rules. Mississippi College.
http://sandbox.mc.edu/~bennet/cs110/tc/orules.html

You might also like