Java Program to perform XOR operation on BigInteger


The java.math.BigInteger.xor(BigInteger val) returns a BigInteger whose value is (this ^ val). This method returns a negative BigInteger if and only if exactly one of this and val are negative. Here, “val” is the value to be XOR'ed with this BigInteger.

Firstly, create two BigInteger objects −

one = new BigInteger("6");
two = new BigInteger("-5");

Now, perform XOR −

three = one.xor(two);

The following is an example −

Example

 Live Demo

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one, two, three;
      one = new BigInteger("6");
      two = new BigInteger("-5");
      three = one.xor(two);
      System.out.println("Result: " +three);
   }
}

Output

Result: -3

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 29-Jun-2020

120 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements