开发者

xor definition (this sentence is to make the title acceptable) [duplicate]

This question already has answers here: 开发者_运维问答 Closed 12 years ago.

Possible Duplicate:

What does ‘^’ do in c# (Enums)?

This may be a noobish question but...nowhere have I seen what Xor means in C++ or C#. I think it might mean and/or and if it does, I'm smart cause that's a blind guess =D. I use C# now but I'm pretty sure xor means the same thing. The problem is - I don't know what xor means. I know that xor is represented by a ^ though. I also would like to know what ^^ means.


Exclusive or between two bits means that the result is 1 if one and only one bit is 1.

The truth table is:

   | 0 | 1
---+---+---
 0 | 0 | 1
 1 | 1 | 0

When you talk about xoring a larger value, it's just taking each bit one at a time, so:

    1111 0000
xor 1010 1010
    ---- ----
  = 0101 1010

For what it's worth, a full list of binary operations:

  • and, 1 only if both its inputs are 1, else 0.
  • or, 0 only if both its inputs are 0, else 1.
  • xor, 1 only if one (not both) of its inputs is 1, else 0.
  • not, 1 only if its input is 0, else 1.

And the truth tables:

and| 0 | 1      or| 0 | 1     xor| 0 | 1     not| 0 | 1
---+---+---    ---+---+---    ---+---+---    ---+---+---
 0 | 0 | 0      0 | 0 | 1      0 | 0 | 1        | 1 | 0 
 1 | 0 | 1      1 | 1 | 1      1 | 1 | 0 


A google search for "define: xor" will point you to http://en.wikipedia.org/wiki/Xor, the fountain of all knowledge. Reading this will give you an insight as to what exclusive-or (XOR) means :)

Goodluck

[edit] And just to clarify, xor does not mean and/or, sorry. And the definition of xor is programming language independent.


XOR stands for 'eXclusive OR'. Exclusive Or operation result is true, only if one of the arguments is true, not both.

Having 1 as the value of true, and 0 as the value of false, bitwise operation gives 1 when only one of the bits at corresponding position is 1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜