Finds the next power of 2 greater than or equal to N.
static int nextPowerOfTwo(int N) { if (N <= 1) return 1; int p = 1; while (p < N) { p *= 2; } return p; }