• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
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
 
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 ]
 
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. :-)
 
author
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!