Java BigInteger andNot()方法

Java BigInteger andNot()方法

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

语法 :

public BigInteger andNot(BigInteger val)

参数: 该方法接受一个参数val BigInteger类型,指的是需要与当前BigInteger相补和的值。

返回值: 该方法用于返回(this & ~val),其中this指的是当前使用该函数的BigInteger,val是作为参数传递给该函数的BigInteger。

例子

输入: value1 = 2300, value2 = 3400
输出: 180
解释:
2300的二进制=100011111100
3400的二进制符号2的补码是1111011010110111。
100011111100和11111010110111的和=10110100
10110100的十进制=180。

输入: value1 = 432045, value2 = 321076
输出: 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

参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#andNot(java.math.BigInteger).

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程