Skip to content

Instantly share code, notes, and snippets.

@ferryzhou
Created January 29, 2013 15:41
Show Gist options
  • Save ferryzhou/4665191 to your computer and use it in GitHub Desktop.
Save ferryzhou/4665191 to your computer and use it in GitHub Desktop.
next power of 2
int nextpow2 (int x) {
if (x < 0)
return 0;
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment