BigInteger flipBit() Method in Java Last Updated : 20 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Prerequisite: BigInteger Basics The java.math.BigInteger.flipBit(index) method returns a BigInteger which is used to flip a particular bit position in a BigInteger. This method Computes (bigInteger ^ (1<<n)). The bit at index n of binary representation of the bigInteger will be flipped. That is, if the bit position is 0 it will be converted to 1 and vice versa.Syntax: public BigInteger flipBit(int index) Parameter:The method accepts one parameter index of integer type and refers to the position of the bit to be flipped.Return Value: The method returns the bigInteger after flipping its bit at position index.Throws: The method throws an ArithmeticException when the value of index is negative.Examples: Input: value = 2300 , index = 1 Output: 2302 Explanation: Binary Representation of 2300 = 100011111100 bit at index 1 is 0 so flip the bit at index 1 and it becomes 1. Now Binary Representation becomes 100011111110 and Decimal equivalent of 100011111110 is 2302 Input: value = 5482549 , index = 5 Output: 5482517 Below program illustrate flipBit(index) method of BigInteger. Java /* *Program Demonstrate flipBit() method of BigInteger */ import java.math.*; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger biginteger = new BigInteger("5482549"); // Creating an int i for index int i = 5; // Call flipBit() method on bigInteger at index i // store the return BigInteger BigInteger changedvalue = biginteger.flipBit(i); String result = "After applying flipBit at index " + i + " of " + biginteger+ " New Value is " + changedvalue; // Print result System.out.println(result); } } Output: After applying flipBit at index 5 of 5482549 New Value is 5482517 Reference:https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#clearBit(int) Comment More infoAdvertise with us Next Article BigInteger flipBit() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-lang package Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger clearBit() Method in Java Prerequisite: BigInteger BasicsThe clearBit() method returns a BigInteger which is used to clear a particular bit position in a BigInteger. The bit at index n of binary representation of BigInteger will be cleared means converted to zero. Mathematically we can say that it is used to calculate this 2 min read BigInteger bitCount() Method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.bitCount() method returns number of bits in the two's complement representation of this BigInteger that differ from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.Syntax: public int bitCount() Para 1 min read BigInteger bitLength() Method in Java The java.math.BigInteger.bitLength() method returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. The bitLength method Computes (cei 1 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 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 2 min read BigInteger xor() Method in Java Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise 2 min read BigInteger and() Method in Java The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as p 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 setBit() Method in Java 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 BigInt 2 min read BigInteger negate() Method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.negate() method returns a BigInteger whose value is (- this). negate() method will change the signed bit of BigInteger. Syntax: public BigInteger negate() Parameters: The method does not accept any parameter. Return Value: The method returns t 1 min read Like