Here you can find the source of nextPowerOfTwoExact(int n)
Parameter | Description |
---|---|
n | the number to find the next power of two for |
public static int nextPowerOfTwoExact(int n)
//package com.java2s; //License from project: Apache License public class Main { /**//w ww. ja v a2s .c o m * Finds the first power of two that is equal to or greater than n. * @param n the number to find the next power of two for * @return the next power of two after or equal to n, with a minimum of 0 */ public static int nextPowerOfTwoExact(int n) { int highest = Integer.highestOneBit(n); return (highest == Integer.lowestOneBit(n)) ? highest : highest << 1; } }