Java Program to implement OR operation on BigInteger


TheBigInteger.or(BigInteger val) returns a BigInteger whose value is (this | val). This method returns a negative BigInteger if and only if either this or val is negative.

Here, “val” is the value to be OR'ed with this BigInteger.

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 = one.or(one);
      System.out.println("Result (or operation): " +two);
   }
}

Output

Result (or operation): 6

Let us see another example −

Example

 Live Demo

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger bi1, bi2, bi3;
      bi1 = new BigInteger("9");
      bi2 = new BigInteger("16");
      bi3 = bi1.or(bi2);
      String str = "OR operation on " + bi1 +" and " + bi2 + " gives " +bi3;
      System.out.println( str );
   }
}

Output

OR operation on 9 and 16 gives 25

Updated on: 29-Jun-2020

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements