isPowerOfTwo function

bool isPowerOfTwo(
  1. int n
)

Returns whether n is a power of two.

Implementation

bool isPowerOfTwo(int n) => n != 0 && (n & (n - 1) == 0);