Skip to main content

Is Power of Two

Definition​

The Power of Two Algorithm determines whether a given integer is a power of two. It leverages bitwise operations for efficiency and simplicity

Practice​

isPowerOfTwo(x):
if x <= 0:
return false
return (x & (x - 1)) == 0