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

java.math.BigInteger.andNot(BigInteger val)方法返回一个BigInteger,其值为(this&〜val),其中该值是当前使用该函数的BigInteger的值,而val是作为参数传递给该函数的bigInteger 。此方法等效于and(val.not()),是为了方便进行掩膜操作。当且仅当此值为负且val为正时,此方法才返回负的BigInteger。 andNOT()方法对当前bigInteger和作为参数传递的bigInteger的NOT值应用按位与运算。

用法:

public BigInteger andNot(BigInteger val)

参数:该方法接受一个参数val BigInteger类型,表示需要与当前BigInteger进行补充和与的值。

返回值:该方法用于返回(this&〜val)到当前使用该函数的BigInteger,而val是作为参数传递给函数的bigInteger。

例子:

Input: value1 = 2300, value2 = 3400

Output: 180

Explanation:

Binary of 2300 = 100011111100

Not of 3400 in binary signed 2's complement is 1111001010110111

AND of 100011111100 and 1111001010110111= 10110100

Decimal of 10110100 = 180.

Input: value1 = 432045, value2 = 321076

Output: 135561

以下示例程序旨在说明BigInteger的andNot()方法。

/*

*Program Demonstrate notNot() method of BigInteger

*/

import java.math.*;

public class GFG {

public static void main(String[] args)

{

// Create 2 BigInteger objects

BigInteger biginteger = new BigInteger("2300");

BigInteger val = new BigInteger("3400");

// Call andNot() method to find this & ~val

BigInteger finalvalue = biginteger.andNot(val);

String result = "Result of andNot operation between " +

biginteger + " and "+ val + " is " + finalvalue;

// Print the result

System.out.println(result);

}

}

输出:

Result of andNot operation between 2300 and 3400 is 180

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值