Java BigInteger getLowestSetBit()方法
java.math.BigInteger.getLowestSetBit() 方法返回此BigInteger的最右边(最低阶)设置位的索引。这意味着该方法返回最右边的设置位右侧的零位或未设置位的数量。如果BigInteger不包含任何设置位,那么这个方法将返回-1。该方法计算(thisBigInteger==0?-1 : log2(thisBigInteger & -thisBigInteger)) .
语法 :
public int getLowestSetBit()
参数: 该方法不接受任何参数。
返回值: 该方法返回这个BigInteger中最右边的设置位的索引。
例子
输入 : value = 2300
输出 : 2
解释:
2300的二进制表示=100011111100
最低的设定位指数是2
输入 : value = 35000
输出 : 3
下面的程序说明了BigInteger的getLowestSetBit()方法。
// Program to illustrate the getLowestSetBit()
// method of BigInteger
import java.math.*;
public class GFG {
public static void main(String[] args)
{
// Create BigInteger object
BigInteger biginteger = new BigInteger("2300");
// Call getLowestSetBit() method on bigInteger
// Store the return value as Integer lowestsetbit
int lowestSetbit = biginteger.getLowestSetBit();
String lsb = "After applying getLowestSetBit on " + biginteger +
" we get index of lowest set bit = " + lowestSetbit;
// Printing result
System.out.println(lsb);
}
}
输出。
After applying getLowestSetBit on 2300 we get index of lowest set bit = 2
**参考资料: **https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#getLowestSetBit()