Java Program to perform AND operation on BigInteger


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

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 29-Jun-2020

104 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements