Hack of the day: Round up to the next power of two
January 19, 2011
Using right shifts, you can compute the next power of two of an 32-bit integer in a very effective way:
For example, the size of a texture should be usually a power of two, so this code comes in very handy.
I find it rather strange that you don’t seem to consider one a power of two (it’s 2⁰ and the smallest integer power of two).
Oopps… fixed it. Thank you.