java log base 2

Java
public static int log2(int x)
{
    return (int) (Math.log(x) / Math.log(2));
}

Source

Also in Java: