C语言 什么是异或和?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17284337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is an XOR sum?
提问by user2517777
I am not sure of the precise definition of this term.
我不确定这个词的确切定义。
I know that a bitwise XOR operation is going bit by bit and taking the XOR of corresponding bits position wise. Is this result termed the 'XOR sum'? If not, what is an XOR sum, and how do you use XOR to implement this addition?
我知道逐位异或运算是逐位进行的,并按位置对相应位进行异或。这个结果被称为“异或和”吗?如果不是,什么是异或和,你如何使用异或来实现这个加法?
回答by haccks
In a bit wise XOR operation:
在有点明智的 XOR 操作中:
a b a^b
-----------
0 0 0
0 1 1
1 0 1
1 1 0
XOR sum refers to successive XOR operations on integers.
Suppose you have numbers from 1to Nand you have to find their XOR sum then for N = 6, XOR sum will be 1^2^3^4^5^6 = 7.
XOR sum 是指对整数进行连续的 XOR 运算。
假设您有来自1to 的数字,N并且您必须找到它们的 XOR 总和,那么对于N = 6,XOR 总和将为1^2^3^4^5^6 = 7。
1 = 001, 2 = 010, 3 = 011, 4 = 100, 5 = 101, 6 = 110
1^2 = 1^2 = 001^010 = 011 = 3
(1^2)^3 = 3^3 = 011^011 = 000 = 0
(1^2^3)^4 = 0^4 = 000^100 = 100 = 4
(1^2^3^4)^5 = 4^5 = 100^101 = 001 = 1
(1^2^3^4^5)^6 = 1^6 = 001^110 = 111 = 7 --> XOR sum
Hope this will help.
希望这会有所帮助。

