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: EASY
Tags: Fundamentals

Mathematics

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):
	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


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
	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


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


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


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


def power_of_two(x):
	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):
	(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):
	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):
	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 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):
	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):
	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


import math
power_of_two = lambda x: not bin(x)[2:].count('1') - 1 if x != 0 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


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


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


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


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('^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):
	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):
	if x == 0:
		return False
	elif x / 2 % 2 == 0 and x % 2 == 0 and (x % 4 == 0) and (x % 8 == 0):
		return True
	elif 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


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