我找到了一些代码here,它完成了我正在寻找的int,但当我插入一个Long时,LSB是第64位,它返回0而不是64.我可以对这种情况进行明确的判断,但肯定有更好的方法.
public class Test{
public static void main(String[] args){
long test = 0b1000000000000000000000000000000000000000000000000000000000000000L;
//this should print "64"
System.out.println(getLSBIndx(test));
}
public static int getLSBIndx(long n){
if(n == 0) return -1;
return (int)((Math.log10(n & -n)) / Math.log10(2)) ;
}
}