This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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
Have you checked out Aspose?
subject: XOR operator
It's not a secret anymore!