^ (XOR) 运算符有什么作用? [英] What does the ^ (XOR) operator do?
本文介绍了^ (XOR) 运算符有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
XOR 执行什么数学运算?
What mathematical operation does XOR perform?
推荐答案
XOR 是一个二元运算,它代表异或",也就是说如果恰好 one 位已设置.
XOR is a binary operation, it stands for "exclusive or", that is to say the resulting bit evaluates to one if only exactly one of the bits is set.
这是它的功能表:
a | b | a ^ b
--|---|------
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0
此操作在一个数的每两个对应位之间执行.
This operation is performed between every two corresponding bits of a number.
示例:7 ^ 10
二进制:0111 ^ 1010
0111
^ 1010
======
1101 = 13
性质:该操作是可交换的、结合的和自逆的.
Properties: The operation is commutative, associative and self-inverse.
也和加法模2一样.
这篇关于^ (XOR) 运算符有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文