什么是XOR总和? [英] What is an XOR sum?

查看:80
本文介绍了什么是XOR总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定该术语的确切定义.

I am not sure of the precise definition of this term.

我知道按位XOR运算将逐位进行,并且将相应位的XOR逐位进行.这个结果称为异或"吗?如果不是,那么XOR的总和是多少?如何使用XOR来实现这种加法运算?

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?

推荐答案

按位进行XOR操作:

a   b   a^b
-----------
0   0    0
0   1    1
1   0    1
1   1    0 

XOR总和是指对整数的连续XOR运算.
假设您有从 1 N 的数字,并且必须找到它们的XOR和,然后对于 N = 6 ,XOR和将为1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6 = 7 .

XOR sum refers to successive XOR operations on integers.
Suppose you have numbers from 1 to N and you have to find their XOR sum then for N = 6, XOR sum will be 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

希望这会有所帮助.

这篇关于什么是XOR总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆