nextPowerOfTwo static method

int nextPowerOfTwo(
  1. int N
)

Finds the next power of 2 greater than or equal to N.

Implementation

static int nextPowerOfTwo(int N) {
  if (N <= 1) return 1;
  int p = 1;
  while (p < N) {
    p *= 2;
  }
  return p;
}