Saturday, December 13, 2025
HomeLanguagesJavaBigInteger getLowestSetBit() Method in Java

BigInteger getLowestSetBit() Method in Java

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)).

Syntax:

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.

Examples:

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:




// 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);
    }
}


Output:

After applying getLowestSetBit on 2300 we get index of lowest set bit = 2

Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#getLowestSetBit()

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7201 POSTS0 COMMENTS
Thapelo Manthata
6898 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS