Checking for overflow conditions have always been tedious to remember logic. Lets deep dive !
Condition for Not Overflowing
But,
- But if youβre storing
number x 10 + unit_digitin a variable , at some point the variable will overflow.- If there is a continuous addition to the LHS of this equation.
- Question we are trying to answer here is :-
- Can we apply some kind of
CHECKto avoid this overflow.
- Can we apply some kind of
- Well we can just apply some maths and the above equation can be written like this :-
Well ! Now
- Now before storing the answer of
number x 10 + unit_digita check can be introduced.- This would make sure, the condition is
NOT OVERFLOWED