<<< Sign Extension | Index | Logical Operations >>> |
Arithmetic operations have a potential to run into a condition known as overflow.
Overflow occurs with respect to the size of the data type that must accommodate the result.
Overflow indicates that the result was too large or too small to fit in the original data type.
For example, when the sum of two positive 8-bit numbers exceeds 127, we have an overflow.
Similarly, if sum of two negative 8-bit numbers is less than or equal to -128, we have an overflow.
When two signed (2's complement) numbers are added, overflow is detected if:
both operands are positive and the result is negative, or
both operands are negative and the result is positive.
When two unsigned numbers are added, overflow occurrs if there is a carry out of the leftmost bit.
<<< Sign Extension | Index | Logical Operations >>> |