List of utility methods to do Power of 2
int | nextPowerOfTwoExact(int n) Finds the first power of two that is equal to or greater than n. int highest = Integer.highestOneBit(n); return (highest == Integer.lowestOneBit(n)) ? highest : highest << 1; |
int | nextPowerOfTwoValue(double value) This method will return the next power of two for the given value, e.g. int power = previousPowerOfTwo(value); return 1 << power; |
int | nextPowerTwo(int initialNum) next Power Two int num = 1; while (num < initialNum) num <<= 1; return num; |