Last active
March 23, 2016 18:28
-
-
Save nitroluke/7a2626e46632383e7ad1 to your computer and use it in GitHub Desktop.
Round up to the nearest power of 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nearesetPow2(x): | |
x = x - 1 | |
for i in [1, 2, 4, 8, 16, 32]: | |
x = x | (x >> i) | |
return x + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment