Skip to content

Instantly share code, notes, and snippets.

@IMelker
Last active September 30, 2019 14:55
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 IMelker/6d4b12c971c2f9309a8917c91e84c5c8 to your computer and use it in GitHub Desktop.
Save IMelker/6d4b12c971c2f9309a8917c91e84c5c8 to your computer and use it in GitHub Desktop.
Get nearest upper power of two to current number
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