p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=574)
-   -   Xor Logical Operator Question (http://p2p.wrox.com/showthread.php?t=88672)

 MinusZero October 25th, 2012 10:29 PM

Xor Logical Operator Question

Hi,

On page 139 of the book it talks about Logical Operators.

In the definition of Xor (^) it states that "It returns true if one of its operands is true and the other is false".

It doesnt explain how Xor returns false though.

Logically speaking, if both operands are true or both operands are false, does that return a false Xor??

Also, with OR and XOR, are you limited to only two operands for comparison? I would assume with AND you could have more than two.

 Rod Stephens October 25th, 2012 11:53 PM

Quote:
 In the definition of Xor (^) it states that "It returns true if one of its operands is true and the other is false". It doesnt explain how Xor returns false though.
Sorry, it returns false otherwise. In other words, it returns false if both are true or both are false.

The truth table is:
T ^ T = F
T ^ F = T
F ^ T = T
F ^ F = F
Quote:
 Also, with OR and XOR, are you limited to only two operands for comparison? I would assume with AND you could have more than two.
All of these operators take only 2 arguments (and "not" takes 1) but you can chain them together just like you can with + or -. For example:
A ^ B ^ C ^ D
is equivalent to:
((A ^ B) ^ C) ^ D
You can do similar things for || and &&.

 MinusZero October 28th, 2012 07:16 PM

Thanks, that helps me alot! :)

 All times are GMT -4. The time now is 12:28 AM.