isPowerOfTwo method

bool isPowerOfTwo (int n)

Returns true if n is a power of 2.

Implementation

static bool isPowerOfTwo(int n) {
  if ((n & (n - 1)) == 0) return true;
  return false;
}