views:

203

answers:

2

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.

+2  A: 

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.

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

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?

FredOverflow