Last active
August 29, 2015 13:59
-
-
Save t0lkman/10963573 to your computer and use it in GitHub Desktop.
Javascript power of two check
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
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