Java BigInteger flipBit() method

The flipBit() method of Java BigInteger class is used to flip a particular bit position in a BigInteger.This method returns the BigInteger after flipping its bit at index n.

Syntax:

Parameter:

n- The position of the bit to be flipped

Return value

This method returns a BigInteger object whose value is, this ^ (1<< n).

Throws:

ArithmeticException? if n is negative.

Example 1

Test it Now

Output:

FlipBit operation on 5 at index 1 gives  7

Example 2

Test it Now

Output:

java.lang.ArithmeticException: Negative bit address

Next TopicJava BigInteger




Latest Courses