Skip to content

Instantly share code, notes, and snippets.

@jiemojiemo
Created November 1, 2018 13:01
Show Gist options
  • Save jiemojiemo/bd5ddc47cb2f88a39aa3141bdf832abe to your computer and use it in GitHub Desktop.
Save jiemojiemo/bd5ddc47cb2f88a39aa3141bdf832abe to your computer and use it in GitHub Desktop.
Check if a number is a power of two
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