BigInteger setBit() Method in Java Last Updated : 03 Mar, 2022 Comments Improve Suggest changes Like Article Like Report The java.math.BigInteger.setbit(index) method returns a Big-integer whose value is equivalent to this Big-integer with the designated bit set. The method computes (this | (1<<n)). The bit at index n of binary representation of Big-integer will be set means converted to 1. Syntax: public BigInteger setbit(int n) Parameters: The method takes one parameter n which refers to the index of the bit that is needed to be set.Return Value: The method returns the BigInteger value after setting the bit position n.Exceptions: The method might throw an ArithmeticException when n is negative.. Examples: Input: value = 2300 index = 1 Output: 2302 Explanation: Binary Representation of 2300 = 100011111100 bit at index 1 is 0 so set the bit at index 1 Now Binary Representation becomes 100011111110 and Decimal equivalent of 100011111110 is 2302 Input: value = 5482549 index = 1 Output: 5482551 Below program illustrate the setBit(index) method of BigInteger: Java // Program to demonstrate setBit() method of BigInteger import java.math.*; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger biginteger = new BigInteger("2300"); // Creating an integer i for index int i = 1; // Calling setBit() method on bigInteger at index i // store the return BigInteger BigInteger changedvalue = biginteger.setBit(i); String result = "After applying setBit at index " + i + " of " + biginteger+ " New Value is " + changedvalue; // Displaying the result System.out.println(result); } } Output: After applying setBit at index 1 of 2300 New Value is 2302 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#setBit(int) Comment More infoAdvertise with us Next Article BigInteger setBit() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java-math Java-BigInteger Java-math-package +1 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger testBit() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.testBit(index) method returns true if and only if the designated bit is set. This method Computes (this & (1<<n)) != 0). Syntax: public boolean testBit(int n) Parameter: The method takes one parameter n of integer type which refers 2 min read BigInteger not() Method in Java The java.math.BigInteger.not() method is used to find the bitwise-NOT of a BigInteger. This method returns a negative value if and only if this BigInteger is non-negative. The BigInteger.not() method apply bitwise Not operation upon the current bigInteger. Syntax: public BigInteger not() Parameters: 1 min read BigInteger shiftRight() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.shiftRight(int n) method returns a BigInteger whose value is (this >> n). The shift distance, n, may be negative, in which case this method performs a left shift. The shiftRight() method will move each digit in a number's binary represe 2 min read BigInteger shiftLeft() Method in Java The java.math.BigInteger.shiftLeft(int n) method returns a BigInteger whose value is (this << n). The shift distance, n, may be negative, in which case this method performs a right shift.shiftLeft() method will moves each digit in a number's binary representation left by n times and the last b 2 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read Like