Java程序在BigInteger上实现andNot运算
TheBigInteger.andNot(BigInteger val)返回一个BigInteger,其值为(this & ~val)。此方法等效于and(val.not()),作为掩码操作的简便方法而提供。仅当this为负而val为正时,此方法才返回一个负的BigInteger。此处,“val”是要取反并与this BigInteger进行AND运算的值。
以下是示例−
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two, three;
one = new BigInteger("12");
two = new BigInteger("6");
three = one.andNot(two);
System.out.println("Result (andNot operation): " +three);
}
}输出
Result (andNot operation): 8
让我们看另一个示例 -
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger bi1, bi2, bi3;
bi1 = new BigInteger("9");
bi2 = new BigInteger("2");
bi3 = bi1.andNot(bi2);
String str = "Result of andNot operation is " +bi3;;
System.out.println( str );
}
}输出
Result of andNot operation is 9
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP