java.math.BigInteger.and(BigInteger val)方法返回一個BigInteger,其值為兩個BigInteger的bitwise-AND。如果兩個BigIntegers均為負數,則此方法返回負數。 and()方法對作為參數傳遞的當前bigInteger和bigInteger應用bitwise-AND操作。
用法:
public BigInteger and(BigInteger val)
參數:該方法接受BigInteger類型的一個參數val,表示要與當前BigInteger進行“與”運算的值。
返回值:該方法返回兩個BigIntegeres的bitwise-AND的值。
例子:
Input: value1 = 2300, value2 = 3400 Output: 2120 Explanation: Binary of 2300 = 100011111100 Binary of 3400 = 110101001000 AND of 100011111100 and 110101001000 = 100001001000 Decimal of 100001001000 = 2120. Input: value1 = 432045, value2 = 321076 Output: 296484
下麵的程序用於說明BigInteger的and()方法。
/*
*Program Demonstrate and() method of BigInteger
*/
import java.math.*;
public class GFG {
public static void main(String[] args)
{
// Creates 2 BigInteger objects
BigInteger biginteger = new BigInteger("2300");
BigInteger val = new BigInteger("3400");
// Call and() method to find this & val
BigInteger biggerInteger = biginteger.and(val);
String result = "Result of AND operation between " + biginteger + " and "
+ val + " is " + biggerInteger;
// Print the result
System.out.println(result);
}
}
輸出:
Result of AND operation between 2300 and 3400 is 2120
參考:https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#and(java.math.BigInteger)
相關用法
- Java BigInteger abs()用法及代碼示例
- Java BigInteger mod()用法及代碼示例
- Java BigInteger xor()用法及代碼示例
- Java BigInteger or()用法及代碼示例
- Java BigInteger pow()用法及代碼示例
- Java BigInteger not()用法及代碼示例
- Java BigInteger bitCount()用法及代碼示例
- Java BigInteger hashCode()用法及代碼示例
- Java BigInteger bitLength()用法及代碼示例
- Java BigInteger gcd()用法及代碼示例
- Java BigInteger add()用法及代碼示例
- Java BigInteger equals()用法及代碼示例
- Java BigInteger compareTo()用法及代碼示例
- Java BigInteger longValue()用法及代碼示例
- Java BigInteger remainder()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 BigInteger and() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。