1
$\begingroup$

I am a bit unclear about underflowing in terms of binary representation.

Let's say that an unsigned 8-bit variable gets overflown from the addition of $150+150$.

A signed 8-bit variable gets underflown after the subtraction of $-120-60$.

Now my point is let's think of 8-bit variable, we are subtracting $110-10$. Now let's convert this into an addition, $110+(-10)$. Since $-10$ is $11110110$ and $110$ is $01101110$. If we add these two binary numbers we will have a value after 8th bit to carry, which is I believe an overflown, however the final binary number is equal to $100$ and that's what we want and in terms of decimal value we did not lose anything. In that case do we have a overflow or underflow here?

$\endgroup$
3
  • 3
    $\begingroup$ Underflow makes no sense for integral values. $\endgroup$ Commented Oct 21, 2013 at 16:36
  • 1
    $\begingroup$ @copper.hat That's not quite true: cwe.mitre.org/data/definitions/191.html $\endgroup$ Commented Jan 31, 2020 at 14:23
  • 1
    $\begingroup$ That is overflow, not underflow. $\endgroup$ Commented Jan 31, 2020 at 14:48

3 Answers 3

2
$\begingroup$

Say you have $8$-bits signed integers. The range of representable integers start at $-128$ and ends at $127$.

If you perform $127+1$, you obtain $-128$ : $0111 1111+0000 0001 = 1000 0000$ and the overflow flag is turned on.

If you perform $-128-1$, you obtain $127$ : $1000 0000-0000 0001 = 0111 1111$ and the overflow flag is turned on.

In both cases, these are overflows.

Underflows refer to floating point underflow, where an operation result in a number that is too small to be representable. For example, if the exponent part can represent values from $-127$ to $127$, then any number with absolute value less than $2^{-127}$ may cause underflow.

$\endgroup$
1
2
$\begingroup$

The term arithmetic underflow (or "floating point underflow", or just "underflow") is a condition in a computer program where the result of a calculation is a number of smaller absolute value than the computer can actually store in memory.

$\endgroup$
1
$\begingroup$

You don't have an overflow here: the result will be 01100100. Since the top bit indicates the sign, the addition process is not the same as for unsigned integers.

For example, 01100100+01100100 overflows for signed integers, because we can't carry from the 7th bit into 8th: the 8th bit is the sign. Over unsigned integers, there is no overflow.

Conversely, 01100100+11110110 overflows for unsigned integers, but not for signed ones.

My point is: the process of adding of numbers represented by binary strings depends on what representation is used. (You would not add floating point representations bitwise...)

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.