0
\$\begingroup\$

Two 2's complement numbers having sign bits x and y are added and sign bit of result is z.Then occurence of overflow is indicated by which boolean function? I believed that overflow occurs when the XOR of the sum and carry is 1 ,there is overflow,else no overflow.Keeping this in mind,I came up with the following truth table:

X Y Z Overflow

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 0

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

Is this table correct?

asked Feb 18, 2016 at 20:38
\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

When can an overflow happen?

  • Adding a positive and a negative number yields a number in between them (lower border inclusive), thus no overflow is possible.
  • Adding two positive numbers will always result in a positive number.
  • Adding two negative numbers will always result in a negative number.

-> An overflow is only possible when both summands share the same sign.

Can an overflow wrap around more than once?

In a n-bit 2's complement number,

  • the maximum number is \2ドル^{n-1}-1\$. Adding two of them yields: $2ドル\cdot(2^{n-1}-1)=2^n-2=-2$$
  • the minimum number is \$-2^{n-1}\$. Again adding two of them: $2ドル\cdot(-2^{n-1})=-2^n=0$$

-> In case of an overflow the result will be always negative for positive summands and positive for negative summands.

Conclusion

An overflow has happened if, and only if, both summands have the same sign and the result has the other sign.

answered Feb 18, 2016 at 21:49
\$\endgroup\$
3
  • \$\begingroup\$ So certain cases here will not hold good in the truth table? \$\endgroup\$ Commented Feb 19, 2016 at 4:04
  • \$\begingroup\$ @user1369975 Yes. Only the cases 001 and 110 are overflows. \$\endgroup\$ Commented Feb 19, 2016 at 8:27
  • \$\begingroup\$ Here z indicates sum or carry? \$\endgroup\$ Commented Feb 20, 2016 at 14:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.