BigInteger类或()方法 (BigInteger Class or() method)
or() method is available in java.math package.
or()方法在java.math包中可用。
or() method is used to perform OR operation between the value of this BigInteger and the value of the given BigInteger.
or()方法用于在此BigInteger的值与给定BigInteger的值之间执行“或”运算。
or() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
or()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
or() method does not throw an exception at the time of performing OR operation.
or()方法在执行OR操作时不会引发异常。
Syntax:
句法:
public BigInteger or(BigInteger val);
Parameter(s):
参数:
BigInteger val represents the object by which to perform OR with this BigInteger.
BigInteger val表示与此BigInteger进行“或”运算的对象。
Return value:
返回值:
The return type of this method is BigInteger, it returns BigInteger that holds the value [(this BigInteger) or (BigInteger val)].
此方法的返回类型为BigInteger ,它返回保存值[(this BigInteger)或(BigInteger val)]的BigInteger。
Example:
例:
// Java program to demonstrate the example
// of BigInteger or(BigInteger val) method of BigInteger
import java.math.*;
public class OrOfBI {
public static void main(String args[]) {
// Initialize two variables str1 and str2
String str1 = "10";
String str2 = "4";
// Initialize two BigInteger objects
BigInteger b_int1 = new BigInteger(str1);
BigInteger b_int2 = new BigInteger(str2);
System.out.println("b_int1: " + b_int1);
System.out.println("b_int2: " + b_int2);
// performs logical or (|) operation between
// this BigInteger b_int1 and the given BigInteger
// b_int2 like 10 | 4 so the binary representation
// of 10 is 1010 and for 4 is 0100 so when we perform
// (|) operation between bits it sets 1 when any of the bits
// value is 1 otherwise it sets 0 so the result is
// (1010 | 0100 = 1110)
BigInteger or_val = b_int1.or(b_int2);
System.out.println("b_int1.or(b_int2): " + or_val);
}
}
Output
输出量
b_int1: 10
b_int2: 4
b_int1.or(b_int2): 14
翻译自: https://www.includehelp.com/java/biginteger-or-method-with-example.aspx