Java 程式對 BigInteger 執行 XOR 操作
java.math.BigInteger.xor(BigInteger val) 返回一個 BigInteger,其值為 (this ^ val)。此方法僅當 this 和 val 中恰好有一個為負值時,才返回一個負 BigInteger。此處,val 是要與該 BigInteger 進行 XOR 操作的值。
首先,建立兩個 BigInteger 物件 −
one = new BigInteger("6");
two = new BigInteger("-5");現在,執行 XOR −
three = one.xor(two);
下面是一個示例 −
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two, three;
one = new BigInteger("6");
two = new BigInteger("-5");
three = one.xor(two);
System.out.println("Result: " +three);
}
}輸出
Result: -3
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP