Skip to content

Instantly share code, notes, and snippets.

@nitroluke
Last active March 23, 2016 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitroluke/7a2626e46632383e7ad1 to your computer and use it in GitHub Desktop.
Save nitroluke/7a2626e46632383e7ad1 to your computer and use it in GitHub Desktop.
Round up to the nearest power of 2.
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