VOOZH about

URL: https://www.geeksforgeeks.org/java/biginteger-xor-method-in-java/

⇱ BigInteger xor() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigInteger xor() Method in Java

Last Updated : 11 Jul, 2025

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-XOR operation upon the current BigInteger and BigInteger passed as parameter. 

Syntax:

public BigInteger xor(BigInteger val)

Parameters: The method accepts one parameter val of BigInteger type and refers to the value to be XOR’ed with this BigInteger. 

Return Value: The method returns bitwise-XOR of the current BigInteger with the BigInteger val

Examples:

Input: value1 = 2300 , value2 = 3400
Output: 1460
Explanation:
Binary of 2300 = 100011111100
Binary of 3400 = 110101001000
XOR of 100011111100 and 110101001000 = 10110110100
Decimal of 10110110100 = 1460.

Input: value1 = 54298 , value2 = 64257
Output: 12059

Below program illustrate the xor() method of BigInteger Class: 

Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#xor(java.math.BigInteger)

Comment