In java we didn't have log2n library but we have log10n library, so we can leverage with that

 

public static double log2(double num)

{

     return (Math.log(num)/Math.log(2));

}

 

Enjoy that.

 

Note: if you want to use that correctly, remember with the (double) cast for accuracy.