# Power of two?

Check if number is a power of 2

16 return true

15 return false



**Solution:** Bit wise comparison

```
public boolean powerOfTwo(int num){
    return ((num & (num - 1)) == 0 && num > 0);
}
```

num =      0b 0001 0000

num - 1 = 0b 0000 1111

num & num 1 == 0b 0000 0000



num not power2 = 0b 0001 0100

num - 1 =                 0b 0001 0011&#x20;

num not power2 & num - 1 == 0b 0001 0000
