I use the following function to calculate log base 2 for integers:
public static int log2(int n){ if(n <= 0) throw new IllegalArgumentException();
There is the function in guava libraries:
LongMath.log2()
So I suggest to use it.