Java Data Type Tutorial - Java BigInteger.setBit(int n)








Syntax

BigInteger.setBit(int n) has the following syntax.

public BigInteger setBit(int n)

Example

In the following code shows how to use BigInteger.setBit(int n) method.

/*from w  w  w .j  a va 2s . c  o  m*/

import java.math.BigInteger;

public class Main {

  public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("7");

    // perform setbit operation on bi1 using index 3
    BigInteger bi2 = bi1.setBit(3);

    System.out.println(bi2);
  }
}

The code above generates the following result.