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