Java BigInteger xor() 方法

2025 年 3 月 20 日 | 阅读 2 分钟

Java BigInteger 类的 xor() 方法用于查找两个 BigInteger 的按位异或(Bitwise XOR)。此方法返回一个 BigInteger,其值为 (this ^ val)。

语法

参数

val - 要与此 BigInteger 进行异或运算的值。

返回值

此方法返回 this ^ val。

Exception

不适用

注意:当且仅当 this 和 val 中只有一个为负数时,此方法才返回一个负 BigInteger。

示例 1

输出

XOR operation on 5 and 2 gives 7 

示例 2

输出

XOR operation on 5 and -2 gives -5 

示例 3

输出

XOR operation on -5 and -2 gives 5