• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XOR operator

 
podonga poron
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
podonga poron
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ! is clear now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic