1

我有两个非常大的二进制字符串,如下所示。如何对这些大字符串执行按位异或并以二进制显示结果?

字符串 1。 100011010011000000001011101100101110111111101110101111101000111110110100011000010100010000101010111101000100011111101001110010010011111100110110100010000000011000101000011010100000110100001011001111000001100100101110111101111001010100100010110001001010110000011111011111010001001011101001110001100100011101100101100000011011101111010000001000000111111111110111100101101011010100011010100101000001101001110110011111011111110101010000111011111011011011100111001000011000011011111100101001110001111110001000000101000100110010111011011010100100111000001010110000101111000010110001011100010010110100010111111001000110011100111100111010100111110001110010110111010000010101000111110110110101010101000111110100010010000000110010000010101100101100101100100100110011000101101100000010100010101010011101101110101101111011010010101011001001000001011100011010101100111100110110101101101110000011010101101111

字符串 2。110001010111000100111011101010101010001011010111111000101010101111100100010111010000010100010110111111010000111110000101111000010010111000111110100000000011011100011100011101100010000101101010000000010011100101111011101001111110100100000010110001011000110100100111000001010001101111101101110111100011001101111100101101001110101111111100000010000111011111111111110101101101000000001110110101000100001101000011010000010001010101010001101000101011101011100110000110001000101011000100110111110110101110100001010111010101010011110011001101100010001000001110100111101111000011011101010010000011100000011011100101000101011101001000101100100101010100111010111010010100000010010110111000110011000101011111101110010110010100000110001100111001111101110001101011110001000001010101010110101111011011001101101011101111001010001111101000011101110100001100000001111110111100101010100011101110000011101100100010000010000000100101010110000010011000011110000001010111110110010100101000011001110110010001110000001111011110000011110011110101010010010001000000000010100001100110110001010110010110000100001011000100011110111100111110

4

3 回答 3

9

使用大整数:

BigInteger(String val, int radix)

BigInteger.XOR(BigInteger val)

BigInteger.toString(int radix)

于 2013-06-26T16:41:14.470 回答
8

这听起来像是家庭作业或作业,所以我将提供指导而不是代码:

于 2013-06-26T16:41:04.907 回答
0

IMO 最合适的解决方案是使用 java 的bitset,因为这基本上就是你所拥有的。bitset 具有所有标准的位操作操作,就像普通的 int 一样,但它们可以任意大。将字符串转换为位集可能很烦人(可能只是循环遍历每个字符),但之后剩下的就很容易了,只需使用实例方法xor()然后toString()打印它

于 2013-06-26T16:54:00.413 回答