isPowerOf2 function

bool isPowerOf2(
  1. int x
)

Returns whether x is a power of two: 1, 2, 4, 8, ...

Implementation

bool isPowerOf2(int x) => (x > 0) && ((x & (x - 1)) == 0);