binary overflow?

2b + 2b =

Overflow?

80 + b3 =

Overflow?

ff + 77 =

Overflow?

If there is overflow, note that you should not include the overflow digit in your answer. I'd recommend converting the numbers to binary first, then computing the result (making note of whether or not overflow occurs), and finally converting the lowest 8 bits of the result back into hexadecimal.

1 Answer

Relevance
  • 4 weeks ago

    Overflow usually applies to signed arithmetic.  Assuming you're using twos complement with 8 total bits, (since FF and 80 in hex convert to 8-bit numbers):

    1. 2B + 2B  obviously no overflow.  Each term is positive and less the 30h, so the sum is less than 60h.  No carry, no overflow

    2. 80 + B3 : Overflow.  Sum is 33h with a carry out the high bit but no carry into it.

    I find this one easier to do either in decimal: (-128ssssssssss) + (-77) = -204, which is outside the -128..+127 range.  Also note that adding any negative number the the smallest possible negative number (80h = -128 in this case) *must* overflow.

    3. FF + 77  No overflow.  Easy peasy....you can't overflow adding a positive an negative number.  I'll do the bits on this one, though:

        1111 1111

      +0111 0111

      ---------------

      1 0111 0110

    The sum of the leftmost two bits was 1 + 0, plus a carry in of 1 from the right.  That produced a carry of 1.  The carry in (1) and carry out (1) are the same, so there's no overflow.

    • Login to reply the answers
Still have questions? Get your answers by asking now.