Base de registro de Java 2
public static int log2(int x)
{
return (int) (Math.log(x) / Math.log(2));
}
Cloudy Capuchin
public static int log2(int x)
{
return (int) (Math.log(x) / Math.log(2));
}
// In Math this holds: loga(b) = ln(b) / ln(a) // loga is log with base a
public static int log2(int N) {
// calculate log2 N indirectly
// using log() method
int result = (int)(Math.log(N) / Math.log(2));
return result;
}