Skip to content

Instantly share code, notes, and snippets.

@t0lkman
Last active August 29, 2015 13:59
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 t0lkman/10963573 to your computer and use it in GitHub Desktop.
Save t0lkman/10963573 to your computer and use it in GitHub Desktop.
Javascript power of two check
function isPowerOfTwo(num) {
return num > 0 && (num & (num-1)) === 0;
}
for(var i = 0; i < 1000; i++){
if(isPowerOfTwo(i)){
console.log(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment