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 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:
/* *Program Demonstrate xor() method of BigInteger */import java.math.*; public class GFG { public static void main(String[] args) { // Create 2 BigInteger objects BigInteger biginteger = new BigInteger("2300"); BigInteger val = new BigInteger("3400"); // Call xor() method to find this ^ val BigInteger biggerInteger = biginteger.xor(val); String result = "Result of XOR operation between " + biginteger + " and " + val + " is " + biggerInteger; // Print result System.out.println(result); } } |
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#xor(java.math.BigInteger)
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java.math.BigInteger.modInverse() method in Java
- Java.math.BigInteger.probablePrime() method in Java
- BigInteger signum() Method in Java
- BigInteger shiftRight() Method in Java
- Java 8 | BigInteger divideAndRemainder() method with Examples
- BigInteger abs() Method in Java
- BigInteger modPow() Method in Java
- BigInteger or() method in Java
- BigInteger and() Method in Java
- BigInteger not() Method in Java
- BigInteger andNot() Method in Java
- BigInteger bitCount() Method in Java
- BigInteger bitLength() Method in Java
- BigInteger clearBit() Method in Java
- BigInteger flipBit() Method in Java
- BigInteger negate() Method in Java
- BigInteger setBit() Method in Java
- BigInteger shiftLeft() Method in Java
- BigInteger testBit() Method in Java
- BigInteger getLowestSetBit() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

