Java BigInteger not()方法
java.math.BigInteger.not() 方法用于查找一个BigInteger的位数-NOT。当且仅当该BigInteger为非负值时,该方法返回一个负值。BigInteger.not()方法对当前的bigInteger进行了位数不运算。
语法 :
public BigInteger not()
参数: 该方法不接受任何参数。
返回值: 该方法返回与之配合使用的BigInteger的位数-NOT值。
例子
输入: value = 2300
输出: -2301
解释:
2300的二进制=100011111100
100011111100的非符号2的补码是111011100000011
十进制值=-2301。
输入: value = 567689
输出: -567690
下面的程序说明了BigInteger()的not()方法。
/*
*Program Demonstrate not() method of BigInteger
*/
import java.math.*;
public class GFG {
public static void main(String[] args)
{
// Creates BigInteger object
BigInteger biginteger = new BigInteger("2300");
// Call not() method to find ~this
BigInteger finalvalue = biginteger.not();
String result = "Result of NOT operation on " +
biginteger + " is " + finalvalue;
// Print result
System.out.println(result);
}
}
输出。
Result of NOT operation on 2300 is -2301
参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#and(java.math.BigInteger).