Calculating int next power of two Here is one of the possible solutions:

  public static int getNextPowerOfTwo(int value) {
    int result = value;
    result -= 1;
    result |= result &gt;&gt; 16;
    result |= result &gt;&gt; 8;
    result |= result &gt;&gt; 4;
    result |= result &gt;&gt; 2;
    result |= result &gt;&gt; 1;
    return result + 1;
}


As in your opinion is it good enough or may you suggest better one?
Java has Integer.highestOneBit that can make this a bit simpler:

int highestOneBit = Integer.highestOneBit(value);
if (value == highestOneBit) {
    return value;
}
return highestOneBit &lt;&lt; 1;