I use the following function to calculate log base 2 for integers:
public static int log2(int n){ if(n <= 0) throw new IllegalArgumentException();
Why not:
public static double log2(int n) { return (Math.log(n) / Math.log(2)); }