Description Of BigInteger: getLowestSetBit()
The java.math.BigInteger.getLowestSetBit() returns the index of the rightmost (lowest-order) one bit in this BigInteger (the number of zero bits to the right of the rightmost one bit). It returns -1 if this BigInteger contains no one bits. It computes (this==0? -1 : log2(this & -this))BigInteger.getLowestSetBit() This method returns the index of the rightmost one bit in this BigInteger
Code Example Java BigInteger
import java.math.BigInteger; public class BigIntegerExam { public static void main(String[] args) { BigInteger bi1 = new BigInteger("8");// 1000 BigInteger bi2 = new BigInteger("7");// 0111 BigInteger bi3 = new BigInteger("6");// 0110 // perform getLowestSetBit on bi1, bi2 int i1 = bi1.getLowestSetBit(); int i2 = bi2.getLowestSetBit(); int i3 = bi3.getLowestSetBit(); System.out.println(i1); // output 3 System.out.println(i2); // output 0 System.out.println(i3); // output 1 } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น