In binary addition, overflow occurs when the sum of two binary numbers exceeds the maximum representable value. This happens because binary numbers have a specific range of representable values based on the number of bits they contain.
When the sum exceeds this range, the result cannot be accurately represented, resulting in an overflow.
Example of Binary Overflow
Let's consider a simple 4-bit binary addition, 1101 + 0101, where we want to store the result in a 4 bit register.
The sum of these two numbers is 10010.
However, since we are working with only 4 a bit register, the most significant bit (MSB) of the sum (1) cannot be represented, resulting in overflow.
The result therefore is that we discard the most significant bit (left-most bit), which gives us an answer of 0010.
Overflow
Binary Underflow
On the other hand, underflow occurs when subtraction is performed on binary numbers, and the result is smaller than the minimum representable value.
Just like overflow, underflow happens because binary numbers have limits on the representable values based on the number of bits used.
Suppose we have a 5-bit binary subtraction: 01010 - 10101.
The result of this subtraction is -10011.
However, in a 5-bit representation, the leftmost bit is used to indicate the sign (0 for positive, 1 for negative), and the remaining bits represent the magnitude.
Therefore, -10011 cannot be accurately represented in 5 bits, causing underflow. In such cases, the correct result would involve using additional bits or a different representation to accurately represent the negative value.
Binary underflow occurs when the result of a calculation is too small to be represented in the allocated .