Complete the function `power_of_two`/`powerOfTwo` (or equivalent, depending on your language) that determines if a given non-negative integer is a [power of two](https://en.wikipedia.org/wiki/Power_of_two).  From the corresponding Wikipedia entry:

> *a power of two is a number of the form 2^(n) where **n** is an integer, i.e. the result of exponentiation with number two as the base and integer **n** as the exponent.*

You may assume the input is always valid.

## Examples

~~~if-not:nasm
```python
power_of_two(1024) ==> True
power_of_two(4096) ==> True
power_of_two(333)  ==> False
```
~~~
~~~if:nasm
```
mov edi, 0
call power_of_two    ; returns false (zero)
mov edi, 16
call power_of_two    ; returns true (non-zero)
mov edi, 100
call power_of_two    ; returns false
mov edi, 1024
call power_of_two    ; returns true
mov edi, 20000
call power_of_two    ; returns false
```
~~~

Beware of certain edge cases - for example, `1` is a power of `2` since `2^0 = 1` and `0` is not a power of `2`.

Difficulty: introductory

Starter code:

def power_of_two(x):
	

Solutions:
def power_of_two(x):
    return x != 0 and ((x & (x - 1)) == 0)

def power_of_two(num):
    return bin(num).count('1') == 1


def power_of_two(x):
    return x and (not(x&(x-1)))

def power_of_two(x):
  # your code here
  return x > 0 and (x & (x-1)) == 0

def power_of_two(x):
  # your code here
  return (x &  (x-1) == 0) and (x >  0)

def power_of_two(x):
  return bin(x).count('1')==1

def power_of_two(x):
    while x > 1 and x % 2 == 0:
        x = x // 2
    return x == 1



def power_of_two(x):
  
    if x == 0:
        return False
    elif x & x-1 != 0:
        return False
    else:
        return True
    
    """
    count = 0
    while (x): 
        count += x & 1
        x >>= 1
    if count==1:
        return True
    else:
        return False
   
    string = bin(x)[2:]
    Sum=0
    for x in range(len(string)):
        if string[x]=="1":
            Sum+=1
    if Sum==1:
         return True
    else:
          return False
    """


def power_of_two(x):
    from math import log2, pow
    if not x == 0:
        c = log2(x)
        return c%1 == 0 and pow(2,c) == x #precision here breaks so assume false
    else: 
        return False

power_of_two = lambda x: True if sum(int(i) for i in bin(x) if i.isdigit())==1 else False

def power_of_two(n):
    return n != 0 and n & (n - 1) == 0


def power_of_two(x):
    if x == 0:
        return False
    elif x & x-1 != 0:
        return False
    else:
        return True


import math

def power_of_two(x):
    return False if x == 0 else True if math.pow(2, round(math.log(x, 2))) == x else False

power_of_two = lambda x: x!=0 and not (x & (x-1))

def power_of_two(n):
    return bin(n).count('1') == 1


def power_of_two(x):
  return list(bin(x)).count('1') == 1

power_of_two = lambda x: bin(x).count('1') == 1

def power_of_two(x):
    if(x != 0):
        if (x & (x- 1)) == 0:
            return True
        else : 
            return False
    else:
        return False

def power_of_two(x):
    return 1 == bin(x).count("1")

def power_of_two(x):
    return x if x < 2 else int(bin(x)[3:]) == 0 

def power_of_two(x):
  # your code here
  if str(bin(x))[2:].count("1")==1:
      return True
  else:
      return False

import math
def power_of_two(x):
    if(x == 0):
        return False
    else:
        return not(x & (x - 1))

def power_of_two(x):
    if x == 0:
        return False
    elif x == 1:
        return True
    elif x % 2 == 0:
        return power_of_two(x // 2)
    else:
        return False

def power_of_two(x):
    n, t = 0, 0
    while t < x:
        t = 2**n
        if t == x: return True
        n += 1
    return False 

def power_of_two(x):
    if x == 1: return True
    n = 2
    while n <= x:
        if x==n: return True
        n = n * 2
    return False


def power_of_two(x):
    start = 1
    while start < x:
        start *= 2

    return start == x

def power_of_two(num):
    if num == 0:
        return False
    elif num & num-1 != 0:
        return False
    else:
        return True

def power_of_two(x):
    l = 1
    while l < x:
        l *= 2
    return l == x

def power_of_two(n):
    if n == 0:
        return False
    if n & n - 1:
        return False
    else:
        return True


def power_of_two(x):
    binary = bin(x)
    bits = [ones for ones in binary[2:] if ones == '1']
    if len(bits) == 1:
        return True
    else:
        return False

import math
def power_of_two(x):
    if x == 0:
        return False
    check = int(math.log(x, 2))
    if 2 ** check == x:
        return True
    return False

def power_of_two(x):
  # your code here
    if (x and (x & (x - 1)) == 0):
        return True
    else:
        return False

import math
def power_of_two(x):
    return x == 2**(int(math.log(x,2))) if x > 0 else False

def power_of_two(x):
    if x % 2 and x != 1 : return 0
    while x > 2 :
        x = x//2
        if x % 2 and x != 1 : return 0
  
    return ( x == 2 or x == 1)

def power_of_two(x):
    result = 0
    i  = 0
    while result < x:
        result = 2 ** i
        i += 1
        if result != x:
            continue
        if result == x:
            return True
    return False

def power_of_two(x):
    powers = []
    for i in range(0,5000):
        powers.append(2**i)
    if x in powers:
        return True
    else:
        return False


def power_of_two(x):
    import re
    pattern = re.compile('^0b10*$')
    return re.match(pattern, bin(x)) is not None

def power_of_two(x):
    power = 0
    
    while True:
        some_value = pow(2, power)
        if some_value == x:
            return True
            break
        elif some_value > x:
            return False
            break
        
        power += 1

def power_of_two(x):
    num = 1
    while True:
        if x == num:
            return True
        elif x < num:
            return False
        num <<= 1

def power_of_two(x):
    return bool(x) and x & -x == x

def power_of_two(x):
    start = 2
    while start < x:
        start *= 2
    return start == x or x == 1

def power_of_two(x):
  # your code here
    if x == 0:
        return False
    
    while( x != 1):
        print(x)
        if (x % 2) != 0:
            return False
        else:
            x /= 2
            
    
    return True

def power_of_two(x):
    list_of_powers = []
    for i in range(500):
        list_of_powers.append(2**i)
    if x in list_of_powers:
        return True
    return False


def power_of_two(x):
    if x == 0:
        return False
    elif x == 1:
        return True
    else:
        return x % 8 == 0

def power_of_two(x):
    if x in (0, 1):
        return x
    elif x % 2 == 1:
        return False
    else:
        return power_of_two(x // 2)

import math

def power_of_two(n):
    return (n != 0) and (n & (n-1) == 0)

from math import log2
def power_of_two(x):
    if x<1:
        return False
    return 2**int(log2(x)) == x

def power_of_two(x):
    return x in [2**i for i in range(150) if 2**i<=x]

import math
def power_of_two(x):
    if x == 0:
        return False
    return (x & (x-1) == 0) and x != 0


def power_of_two(x):
    if x == 0:
        return False
    if x == 1:
        return True
    
    while x % 2 == 0:
        x = x // 2
        if x == 1:
            return True
        
    return False

  
def power_of_two(x):
    '''Find if a number can be obtained via 2^n'''
    current_number = 0
    counter = 0
    while current_number <= x:
        current_number = 2**counter
        counter+=1
        if current_number == x:
            return True
    return False  

import math
def power_of_two(x):
    if x<=0:
        return False
    if x>0:
        y=int((math.log(x,2)))
        for i in range(y-1,y+2):
                if 2**i==x:
                    return True
                
                
        return False
        


def power_of_two(x):
    print(x)
    if x==0:
        return False
    elif x==1:
        return True
    while(True):
        if x<=0 or x==1:
            return True
            break
        if x%2==0:
            x=x//2
        else:
            return False

def power_of_two(x):
    return not(x & (x-1)) if x != 0 else False

def power_of_two(x):
    i = 1
    l = [1]
    while i < x:
        i *= 2
        l.append(i)
    return x in l


def power_of_two(x):
    
    while x > 1 :
        if x % 2 :
            return False
        x //= 2
    
    return x != 0

def power_of_two(x):
    return True if x&(x-1)==0 and x!=0 else False

def power_of_two(x):
    return True if "{0:b}".format(x).count('1')==1 else False

import math

def power_of_two(x):
    if x == 1:
        return True
    elif x < 1 or x % 2:
        return False
    return power_of_two(x//2)

import math
def power_of_two(x):
    exp_val = int(math.log(x)/math.log(2)) if x else 0
    return True if x > 0 and 2**exp_val == x else False

def power_of_two(x):
    for i in range(101):
        if 2**i==x:
            return True
    return False

def power_of_two(x):
    if x == 0:
        return False
    
    num = 1
    while num < x:
        num *= 2
    return num == x

def power_of_two(x):
    i = 0
    
    while (pow(2, i) <= x):
        if pow(2, i) == x:
            return True
        i += 1
    
    return False

def power_of_two(x):
    l = [2**i for i in range(0, 500)]
    return x in l

def power_of_two(x):
    if x == 0:
        return False
    else:
        return x & -x == x

from math import log
def power_of_two(x):
    if x < 1: return False
    if str(x)[-1:] in '13579' and x>1: return False
    else:
        return 2**int(log(x,2)) == x

def power_of_two(x):
    
    if x <= 0:
        return False
    if x == 1:
        return True
        
    test = 1
    i = 0
    
    while test <= x:
        test = test * 2
        if test == x:
            return True
    
    return False

import math

power_of_two = lambda x : not (bin(x)[2:].count('1')-1) if x != 0 else False

from math import log2

def power_of_two(x):
  return 2**int(log2(x)) == x if x >= 1 else False

def power_of_two(x):
  for i in range(0,4096):
      if 2**i==x:
          return True
      else:
          pass
  return False

def power_of_two(x):
    
    i = 0
    while True:
        num = 2**i
        if num == x:
            return True
        elif num > x:
            return False
        i += 1

from math import *
def power_of_two(x):
    return x == 2**ceil(log2(x)) if x > 0 else 0

def power_of_two(x: int):
    return bin(x).count('1') == 1

from math import log2
def power_of_two(x):
    if x <= 0:
        return False
    return x == 2**int(log2(x))

powers = []
for i in range(0, 150):
    y = 2**i
    powers.append(y)

def power_of_two(x):
    if x == 0:
        return False
    

    elif x in powers:
        return True
    else:
        return False
  # your code here


import math
def power_of_two(x):
  return x == 2**(int(math.log2(x))) if x > 0 else False

def power_of_two(x):
    exp = 0
    while ( x > 2**exp ):
        exp += 1
    return 2**exp == x

def power_of_two(x):
  p = 1
  while p < x:
      p = p * 2
  return p == x

def power_of_two(x):
  if x == 0:
      return False
  p = 1
  while p < x:
      p = p * 2
  if p == x:
      return True
  else:
      return False


from math import log
def power_of_two(x):
  return (x>0) and 2**int(log(x, 2))==x

def power_of_two(x):
  if x == 0:
      return False
  return bin(x)[3:].find('1') == -1

def power_of_two(x):
  if x == 0: return False
  if x == 1: return True
  if x % 2 != 0: return False
  return power_of_two(x//2)

def power_of_two(x):
    powers = []
    for i in range(0, 1000):
        powers.append(2**i)
    return True if x in powers else False

def power_of_two(x):
  # your code here
  if x==0:
      return False#checking the 1st case
  while (x!=1):
      if (x%2!=0):
        return False#
      x=x//2#//floor division it will give round numbersfor ex:1.5 means it will give 1
  return True

import math

def power_of_two(x):
    if x < 1:
        return False
    if x == 2 or x == 1:
        return True
    if x and (not(x & (x - 1))):
        return True
    else:
        return False

import re

def power_of_two(x):
    return True if re.match(r"^1[0]*$", bin(x)[2:]) else False


def power_of_two(x):
  for i in range(0,128):
      if x == 2**i:
          return True
      elif x < 2**i:
          return False

def power_of_two(x):
    return x&(x-1) == 0 if x != 0 else False

def power_of_two(x):
    if x == 0:
        return False
    while x != 1:
        if x % 2 != 0:
            return False
        x = x // 2
    return True


print(power_of_two(1024))

def power_of_two(x):
  # your code here
  y = 1
  while x >= y:
      if x == y: return True
      y = 2 * y
  return False

def power_of_two(x):
  a = 1
  while a < x:
      a = a*2
  return a == x

def power_of_two(x):
  # your code here
  if x==0:
      return False
  elif (x/2)%2==0 and x%2==0 and x%4==0 and x%8==0:
      return True
  else:
      if x==1:
          return True
      else:
          return False


power_of_two = lambda n: True if n!= 0 and 2 ** round(__import__('math').log(n, 2)) == n else False


power_of_two = lambda n: bin(n).count('1') == 1

def power_of_two(x):
    i = 1
    while i < x:
        i = i * 2
    if i == x:
        return True
    else:
        return False

def power_of_two(x):
    return False if x == 0 else bin(x)[2:].count('1') == 1

   


from math import log

def power_of_two(x):
    return 2 ** int(log(x, 2)) == x if x else False

def power_of_two(x):
  n=1
  while x>n:
      n*=2
  return x==n

def power_of_two(x):
    return x and not bool(x & (x-1))