Simpler version, not that it matters much for your use.

```scala
private def isPowerOf2(n: Int): Boolean = n > 0 && (n & (n-1)) == 0
```