Created
January 29, 2013 15:41
-
-
Save ferryzhou/4665191 to your computer and use it in GitHub Desktop.
next 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
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