Here you can find the source of log2(BigInteger x)
public static int log2(BigInteger x)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static int log2(BigInteger x) { return x.bitLength() - 1; }//from w ww . j a v a2 s .com public static int log2(int x) { return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(x); } }