<分区>
任何人都可以用一个很好的例子来解释这个运算符吗?
我知道这个运算符是什么。我的意思是一个现实生活中的例子。
<分区>
任何人都可以用一个很好的例子来解释这个运算符吗?
我知道这个运算符是什么。我的意思是一个现实生活中的例子。
最佳答案
它是逻辑操作exclusive disjunction
的实现
http://en.wikipedia.org/wiki/Exclusive_or
Exclusive disjunction is often used for bitwise operations. Examples:
- 1 xor 1 = 0
- 1 xor 0 = 1
- 0 xor 1 = 1
- 0 xor 0 = 0
- 1110 xor 1001 = 0111 (this is equivalent to addition without carry)
As noted above, since exclusive disjunction is identical to addition modulo 2, the bitwise exclusive disjunction of two n-bit strings is identical to the standard vector of addition in the vector space (Z/2Z)^4.
In computer science, exclusive disjunction has several uses:
- It tells whether two bits are unequal.
- It is an optional bit-flipper (the deciding input chooses whether to invert the data input).
- It tells whether there is an odd number of 1 bits ( is true iff an odd number of the variables are true).
(以及一大堆其他用途)
关于c# - 什么是 C# exclusive 或 `^` 用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6422329/