- Java.math 包簡介
- Java.math - 列舉
- Java.math - 討論
ava.math.BigInteger.xor() 方法
描述
java.math.BigInteger.xor(BigInteger val) 返回值為 (this ^ val) 的 BigInteger。僅當 this 和 val 中有一個為負時,此方法才會返回負的 BigInteger。
宣告
以下是 java.math.BigInteger.xor() 方法的宣告。
public BigInteger xor(BigInteger val)
引數
val - 要與此 BigInteger 進行異或運算的值。
返回值
此方法返回一個 BigInteger 的值,為 this ^ val。
異常
不適用
示例
以下示例顯示了 math.BigInteger.xor() 方法的用法。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create 3 BigInteger objects
BigInteger bi1, bi2, bi3;
bi1 = new BigInteger("8");
bi2 = new BigInteger("-6");
// perform xor on bi1, bi2 and assign result to bi3
bi3 = bi1.xor(bi2);
String str = "XOR operation " +bi1+ " and " +bi2+ " gives " +bi3;
// print bi3 value
System.out.println( str );
}
}
讓我們編譯和執行上面的程式,將生成以下結果 -
XOR operation 8 and -6 gives -14
java_math_biginteger.htm
廣告