File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes XOR operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "XOR operator" Watch "XOR operator" New topic

XOR operator

podonga poron
Ranch Hand

Joined: May 12, 2008
Posts: 55
class XOR_operator {
public static void main(String[] args) {
System.out.println("xor " + ((true) ^ (true)));

Result = False ??? WTF .. how this operator works ?

thanks !
marc weber

Joined: Aug 31, 2004
Posts: 11343

The "x" in "xor" means "exclusive."

So a^b is true if a is true or b is true, but not if both are true (because then it wouldn't be exclusive).

Or as JLS - 15.22.2 puts it, "the result value is true if the operand values are different; otherwise, the result is false."
[ June 05, 2008: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
podonga poron
Ranch Hand

Joined: May 12, 2008
Posts: 55
thanks ! is clear now
I agree. Here's the link:
subject: XOR operator
jQuery in Action, 3rd edition