先决条件: 大整数基础 这个 xor(BigInteger val) 方法返回两个大整数的按位异或。此方法返回负BigInteger当且仅当当前BigInteger和传入参数id的BigInteger中正好有一个为负时。BigInteger类的xor()方法对当前的BigInteger和作为参数传递的BigInteger应用按位异或操作。
null
语法:
public BigInteger xor(BigInteger val)
参数: 该方法接受一个参数 瓦尔 是BigInteger类型,是指要与此BigInteger进行异或运算的值。
返回值: 该方法返回当前BigInteger与BigInteger的按位异或 瓦尔 .
例如:
Input: value1 = 2300 , value2 = 3400 Output: 1460 Explanation: Binary of 2300 = 100011111100 Binary of 3400 = 110101001000 XOR of 100011111100 and 110101001000 = 10110110100 Decimal of 10110110100 = 1460. Input: value1 = 54298 , value2 = 64257 Output: 12059
下面的程序演示了BigInteger类的xor()方法:
/* *Program Demonstrate xor() method of BigInteger */ import java.math.*; public class GFG { public static void main(String[] args) { // Create 2 BigInteger objects BigInteger biginteger = new BigInteger( "2300" ); BigInteger val = new BigInteger( "3400" ); // Call xor() method to find this ^ val BigInteger biggerInteger = biginteger.xor(val); String result = "Result of XOR operation between " + biginteger + " and " + val + " is " + biggerInteger; // Print result System.out.println(result); } } |
参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#xor(java.math.biginger)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END