Computing the max without if statements | RareSkills Animated Explainer
Computing the max without `if` statements in Solidity
A frequent operation is determining which of two unsigned integers is greater than the other.
We might typically write this as
We could also do it in one line with `max = x > y ? x : y;`.
However, this introduces a branch at the bytecode level, which increases the gas cost in Solidity.
Using a few clever bit manipulation tricks, we can compute the max without a conditional statement.
Learn how to do this in our latest video.
Looking for more gas optimization tricks?