Java Program to perform XOR operation on BigInteger

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 20-Dec-2018 06:23:51
Advertisements