Skip to content

Instantly share code, notes, and snippets.

@ABcDexter
Created November 14, 2016 07:11
Show Gist options
  • Save ABcDexter/dc4aa81863372d50caf980677e79cc6e to your computer and use it in GitHub Desktop.
Save ABcDexter/dc4aa81863372d50caf980677e79cc6e to your computer and use it in GitHub Desktop.
Check whether a given positive integer N is power of 2 or not in log(N) complexity.
def isPow2(num):
rem=num%2
while num>1:
if rem==1:
return False
rem=num%2
num/=2
if num>1:
return False
else:
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment