java biginteger and_Java BigInteger and()用法及代码示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值