我有两个非常大的二进制字符串,如下所示。 如何在这些大字符串上执行按位xor并以二进制显示结果?
字符串1。
100011010011000000001011101100101110111111101110101111101000111110110100011000010100010000101010111101000100011111101001110010010011111100110110100010000000011000101000011010100000110100001011001111000001100100101110111101111001010100100010110001001010110000011111011111010001001011101001110001100100011101100101100000011011101111010000001000000111111111110111100101101011010100011010100101000001101001110110011111011111110101010000111011111011011011100111001000011000011011111100101001110001111110001000000101000100110010111011011010100100111000001010110000101111000010110001011100010010110100010111111001000110011100111100111010100111110001110010110111010000010101000111110110110101010101000111110100010010000000110010000010101100101100101100100100110011000101101100000010100010101010011101101110101101111011010010101011001001000001011100011010101100111100110110101101101110000011010101101111
字符串2. 110001010111000100111011101010101010001011010111111000101010101111100100010111010000010100010110111111010000111110000101111000010010111000111110100000000011011100011100011101100010000101101010000000010011100101111011101001111110100100000010110001011000110100100111000001010001101111101101110111100011001101111100101101001110101111111100000010000111011111111111110101101101000000001110110101000100001101000011010000010001010101010001101000101011101011100110000110001000101011000100110111110110101110100001010111010101010011110011001101100010001000001110100111101111000011011101010010000011100000011011100101000101011101001000101100100101010100111010111010010100000010010110111000110011000101011111101110010110010100000110001100111001111101110001101011110001000001010101010110101111011011001101101011101111001010001111101000011101110100001100000001111110111100101010100011101110000011101100100010000010000000100101010110000010011000011110000001010111110110010100101000011001110110010001110000001111011110000011110011110101010010010001000000000010100001100110110001010110010110000100001011000100011110111100111110
答案 0 :(得分:8)
听起来像家庭作业或作业,所以我会提供指导而不是代码:
StringBuilder
i
charAt(i)
抓住i
0
为字符串构建器,否则将1
附加到其中答案 1 :(得分:8)
答案 2 :(得分:0)
IMO最合适的解决方案是使用java bitset,因为这基本上就是你所拥有的。 bitsets具有所有标准位操作操作,如普通int,但它们可以根据需要大小。将字符串转换为bitset可能很烦人(可能只是循环遍历每个字符)但之后很容易使用实例方法xor()
然后toString()
来打印它