3

Binary values are in 2s Complement form.

If I am to add 110001 (-15) and 101110 (-18), and the answer has to be stored in a 6-bit integer, is this an underflow/overflow.

1
  • Yes, it is. But I solved it, got an answer of, in decimal, -33. Since the lower range of a 6-bit 2s complement integer is -32, according to me it is an underflow, but according to my prof. solution notes, its not. I just want to confirm. Commented Apr 27, 2010 at 23:41

3 Answers 3

2

This is overflow, your professor is correct. You are storing more bits that can be held in the alloted space (even though the number that the bits represent is negative.)

Underflow is when bits get zero'd out through shifting on big math. Very common in fixed point math. Divide a very small number by a very big number and you will quite often get a 0. That is underflow.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 That's what I was going to say. Underflow is a different concept, more commonly related to floating point math.
1

There is a a good example discussed to add two registers with contents -70 and -90 and store it in third register.

Let's assume R1[8 bits] = -70 R2[8 bits] = -90 Result[9 bits] = -160, an extra bit for overflow.

This example is discussed on overflow_signed_detection page on ref 1 below. With the rules discussed on this page, the example can be scaled to any two signed decimal numbers.

Comments

0

EDIT: I just realized that -33 is too large for 6 bits, so the result is NOT -33 but +31, and thus it is definitely an overflow :)

Adding two numbers and getting the correct result if definitely NOT an overflow. An example of an overflow is adding two negative numbers and getting a positive number as a result (or vice versa).

For example, if you add the two positive numbers 0x7fffffff and 0x00000001, you get the negative number 0x80000000, which is definitely wrong and thus an overflow.

Maybe you are confusing overflow with carry?

Comments

Your Answer

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.