Created
November 1, 2018 13:01
-
-
Save jiemojiemo/bd5ddc47cb2f88a39aa3141bdf832abe to your computer and use it in GitHub Desktop.
Check if a number is a power of two
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
def is_power2(num): | |
'states if a number is a power of two' | |
return ((num & (num - 1)) == 0) and num != 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment