Concept Flow - Integer overflow and underflow
Start with integer value
Perform arithmetic operation
Check if result > max value?
Yes→Overflow occurs: wraps to min value
Result is min value
Check if result < min value?
Yes→Underflow occurs: wraps to max value
Result is max value
Result is within range
Use result
End
Start with an integer, do math, then check if it goes beyond max or min limits. If yes, overflow or underflow happens, wrapping the value around.