I am dealing with an algorithm that operates on unsigned 256-bit integers, and I need to write a function that computes the value of the given formula
uint256 compute(uint16 x) {
return floor(exp2(x / 256)) - 1;
}
We can see that the equation preserves the variable bounds (compute(0) == 0
, compute(65535) == 1<<255
). The division should be treated as division of rational numbers, not integers.
The presented syntax is pseudo-C, but I'm looking for a general algorithmic aproach that could be used in other languages.
Thank you very much for your help and time.