So I've got this situation: a=b*39216/100000 Both a and b are uint8 variables Is there a value I could assign to b so that a is>100 afterwards? And then a has to be >100
I've thought about somehow creating an underflow in this situation but can't really see how
Answers
Since both a
and b
are uint8
variables, their values are constrained to the range of 0 to 255 inclusive. Given this constraint, let's analyze the expression:
a = b * 39216 / 100000
To make a
greater than 100, we need to find a value of b
that results in a
being greater than 100.
Let's solve the inequality:
b * 39216 / 100000 > 100
Rearranging, we get:
b > 100 * 100000 / 39216
Now, let's calculate the value on the right-hand side:
b > 254.9 (approximately)
Since b
must be an integer value (as it's of type uint8
), the smallest value of b
that satisfies this inequality is 255.
So, by setting b = 255
, you'll ensure that a
will be greater than 100 after the computation.