I use the following function to calculate log base 2 for integers:
public static int log2(int n){ if(n <= 0) throw new IllegalArgumentException();
Some cases just worked when I used Math.log10:
public static double log2(int n) { return (Math.log10(n) / Math.log10(2)); }