prerequisite : BigInteger Basics
The java.math.BigInteger.getLowestSetBit() method returns the index of the rightmost (lowest-order) set bit of this BigInteger. It means this method returns the number of zero or unset bits to the right of the rightmost set bit. If the BigInteger contains no set bit then this method will return -1. The method computes (thisBigInteger==0? -1 : log2(thisBigInteger & -thisBigInteger)).
public int getLowestSetBit()
Parameters: The method does not accept any parameters.
Return Value: The method returns the index of the rightmost set bit in this BigInteger.
Input: value = 2300 Output: 2 Explanation: Binary Representation of 2300 = 100011111100 The lowest set bit index is 2 Input: value = 35000 Output: 3
Below program illustrate the getLowestSetBit() method of BigInteger:
After applying getLowestSetBit on 2300 we get index of lowest set bit = 2
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.