Java中的BigInteger和()方法

这个 JAVA数学大整数。和(大整数val) 方法返回一个BigInteger,其值为按位且由两个BigInteger组成。如果两个大整数都是负数,则此方法返回负数。and()方法对当前的bigInteger和作为参数传递的bigInteger应用按位and运算。 语法:

public BigInteger and(BigInteger val)

参数: 该方法接受一个参数 瓦尔 是指要与当前BigInteger进行and运算的值。 返回值: 该方法返回两个大整数的按位AND值。 例如:

Input: value1 = 2300, value2 = 3400Output: 2120Explanation:Binary of 2300 = 100011111100Binary of 3400 = 110101001000AND of 100011111100 and 110101001000 = 100001001000Decimal of 100001001000 = 2120.Input: value1 = 432045, value2 = 321076Output: 296484

下面的程序用来说明BigInteger的and()方法。

JAVA

/*
*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.biginger)

© 版权声明
THE END
喜欢就支持一下吧,技术咨询可以联系QQ407933975
点赞6 分享