Java Program to perform AND operation on BigInteger

Java 8Object Oriented ProgrammingProgramming

The java.math.BigInteger.and(BigInteger val) returns a BigInteger whose value is (this & val). This method returns a negative BigInteger if and only if this and val are both negative. Here, “val” is the value to be AND'ed with this BigInteger.

First, create BigInteger objects −

BigInteger one, two, three;
one = new BigInteger("12");
two = new BigInteger("6");

Perform AND operation on first and second object −

three = one.and(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("12");
      two = new BigInteger("6");
      three = one.and(two);
      System.out.println("Result: " +three);
   }
}

Output

Result: 4
raja
Published on 20-Dec-2018 07:31:03
Advertisements