Java BigInteger getLowestSetBit() method

The getLowestSetBit() method of Java BigInteger class is used to get the position of the rightmost set bit of this BigInteger. This method returns an integer whose value is the total number of reset bits (0's) to the right of the rightmost set bit. This method computes (this == 0 ? -1 : log2(this & -this)).

Syntax:

Parameter:

NA.

Returns:

This method returns the index of the rightmost set bit in this BigInteger.

Exception:

NA

Note: This method returns -1 if this BigInteger contains no one bits.

Example 1

Test it Now

Output:

Index of the rightmost set bit in 8 is 3
Index of the rightmost set bit in 1 is 0
Index of the rightmost set bit in 10 is 1

Example 2

Test it Now

Output:

Index of the rightmost set bit in 0 is -1
Index of the rightmost set bit in 15 is 0

Next TopicJava BigInteger




Latest Courses