**C++**

Using how doubles represent numbers.

```
bool isPowerOfTwo(double n) {
return n > 0 && !(*(long long*)&n << 12);
}
```

**Python Golf**

Using n&-n and chained comparisons.

```
def isPowerOfTwo(self, n):
return-n&n==n>0
```

**Python**

Assigning a set's method.

```
class Solution:
isPowerOfTwo = {1<<e for e in range(31)}.__contains__
```