Java BigInteger xor() Method

The xor() method of Java BigInteger class is used to find the Bitwise XOR of two BigIntegers. This method returns a BigInteger whose value is (this ^ val).

Syntax:

Parameter:

val - value to be XOR'ed with this BigInteger.

Returns:

This method returns this ^ val.

Exception:

NA

Note: This method returns a negative BigInteger if and only if exactly one of this and val are negative.

Example 1

Test it Now

Output:

XOR operation on 5 and 2 gives 7 

Example 2

Test it Now

Output:

XOR operation on 5 and -2 gives -5 

Example 3

Test it Now

Output:

XOR operation on -5 and -2 gives 5  

Next TopicJava BigInteger




Latest Courses