4

BigInteger类型的两个二进制数做异或操作后，希望得到的返回结果也为二进制数形式，怎样得到？！

BigInteger类型的两个二进制数做异或操作后，希望得到的返回结果也为二进制数形式，怎样得到？！

public class Test {
public static void main(String[] args) {

String thisstrhash = "0000011001111101111100101011111010000110110101110101110001100100";
String otherstrhash = "0000011001111101101100101011111010000110110101110101111001001100";

BigInteger thisintegerhash = new BigInteger(thisstrhash);
BigInteger otherintegerhash = new BigInteger(otherstrhash);

BigInteger x =  thisintegerhash.xor(otherintegerhash);

System.out.println("thisintegerhash:\t" + thisintegerhash);
System.out.println("otherintegerhash:\t" + otherintegerhash);

System.out.println("Long.toBinaryString(otherintegerhash.longValue()):\t" + Long.toBinaryString(otherintegerhash.longValue()));

System.out.println("thisintegerhash.xor(otherintegerhash):\t" + x);

System.out.println(Long.toBinaryString(x.longValue()));

}

thisintegerhash: 11001111101111100101011111010000110110101110101110001100100

otherintegerhash: 11001111101101100101011111010000110110101110101111001001100

Long.toBinaryString(otherintegerhash.longValue()): 1100010011001111000010000111011101011110010110010110010001100

thisintegerhash.xor(otherintegerhash): 81369376257636037022054442224360583791938030024

1001111101101101110000000000000001011011111110101100100111001000

BigInteger x =  thisintegerhash.xor(otherintegerhash);

x的结果为：00000000000010000000000000000000000000000000000001000101000 （两个数做异或后正确答案应该是这样）

thisintegerhash.xor(otherintegerhash): 81369376257636037022054442224360583791938030024

BigInteger类型的两个二进制数做异或操作后，希望得到的返回结果也为二进制数形式，并且结果正确。这个怎样得到？！

hiqj

a="...",b="....";

c=new BigInteger(a,2).xor(new BigInteger (b,2)).toString(2);

d="0000000000(64个0)";

c=d.subString(0,64-c.length)+c;

#### 引用来自“sxgkwei”的评论

a="...",b="....";

c=new BigInteger(a,2).xor(new BigInteger (b,2)).toString(2);

d="0000000000(64个0)";

c=d.subString(0,64-c.length)+c;

返回此 BigInteger 的给定基数的字符串表示形式。