Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between !=(Not equal) and ^(XOR)

 
Jonah Hague
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there another difference between an inequality test on booleans and an Exclusive OR besides the obvious fact that a XOR is only for booleans and a NOT EQUAL is also for ints, floats,...
example:


both of these if-statements seem to accomplish the same thing
 
Nickolas Case
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XOR allows you to test against more than one argument and evaluates to true if and only if one of the arguments you are checking against is true.
For example:



Whereas != is only one argument at a time



Hope this helps.
[ April 28, 2008: Message edited by: Nickolas Case ]
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just for accuracy, in your sample code shouldn't it be:



Using the equals "==" rather than the assignment "=" operator?
 
Nickolas Case
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it should. Adjusted accordingly. :-)
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nickolas

if(true == false^true)

is exactly the same as

if(false^true)

which is equivalent to

if(false!=true)

which again is exactly the same as

if(true == (false!=true))

So I really don't understand the distinction you are making.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic