• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it should. Adjusted accordingly. :-)
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic