Well, the interesting part: โHow to get a maximum degree of 2 that is less than or equal to my upper boundโ and the same for the least degree of 2 that is greater than or equal to my lower bound.
And itโs easy to do without loops. For 32-digit unsigned numbers:
floor(x): ; floor power of 2
x = x | (x >> 1)
x = x | (x >> 2)
x = x | (x >> 4)
x = x | (x >> 8)
x = x | (x >> 16)
return x - (x >> 1)
ceil(x): ; ceiling power of 2
x = x - 1
x = x | (x >> 1)
x = x | (x >> 2)
x = x | (x >> 4)
x = x | (x >> 8)
x = x | (x >> 16)
return x + 1
You wonโt be able to go around the loop to print numbers, but, well, good.
source
share