Last active
September 30, 2019 14:55
-
-
Save IMelker/6d4b12c971c2f9309a8917c91e84c5c8 to your computer and use it in GitHub Desktop.
Get nearest upper power of two to current number
This file contains hidden or 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
long NUP2(long x) { | |
x--; | |
for (int p=1; p<32; p<<=1) x |= (x >> p); | |
return ++x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment