Java.math.BigInteger.and() Method



Description

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.

Declaration

Following is the declaration for java.math.BigInteger.and() method.

public BigInteger and(BigInteger val)

Parameters

val − Value to be AND'ed with this BigInteger.

Return Value

This method returns a BigIntger object of value, this & val.

Exception

NA

Example

The following example shows the usage of math.BigInteger.and() method.

package com.tutorialspoint;

import java.math.*;

public class BigIntegerDemo {

   public static void main(String[] args) {

      // create 3 BigInteger objects
      BigInteger bi1, bi2, bi3;  

      // assign values to bi1, bi2
      bi1 = new BigInteger("6"); //110
      bi2 = new BigInteger("3"); //011

      // perform and operation on bi1 using bi2
      bi3 = bi1.and(bi2);
	  
      String str = "Result of and operation is " +bi3;;

      // print bi3 value
      System.out.println( str );
   }
}

Let us compile and run the above program, this will produce the following result −

Result of and operation is 2
java_math_biginteger.htm
Advertisements