Skip to content

Instantly share code, notes, and snippets.

@sikanrong
Created July 30, 2018 15:52
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 sikanrong/bf790b6c25ad5bd24265e51c4bb61698 to your computer and use it in GitHub Desktop.
Save sikanrong/bf790b6c25ad5bd24265e51c4bb61698 to your computer and use it in GitHub Desktop.
//Smallest power of 2 greater than or equal to n
//https://www.geeksforgeeks.org/smallest-power-of-2-greater-than-or-equal-to-n/
var smallestPowerOfTwo = function(x){
var bitPlaces = 0;
while(x){
bitPlaces++;
x >>= 1;
}
return 1 << bitPlaces;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment