Exclusive or in if statement?

This is a discussion on Exclusive or in if statement? within the C Programming forums, part of the General Programming Boards category; Is it possible to use an Exclusive or in an if statment? I can't find any refference to it. Since ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    847

    Exclusive or in if statement?

    Is it possible to use an Exclusive or in an if statment? I can't find any refference to it. Since bitwise or is | and Boolean or is || I tried
    Code:
    if (a ^^ b)
    But that gives a syntax error.
    It would make sense for this to be part of the c language so I'm guesing there is an obvious anser.

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    India
    Posts
    515
    here, a logical exclusive or would be !=
    an exclusive or returns 0 if both values are the same, and 1 if both the values are not equal( in terms of the truth tables taking 1,0 and considering all possible combos of a and b) if we consider != , if a is equal to b or vice versa, it will return 0, else it will return something other that 0, generally 1. so inside the if statement, != can be used as logical exclusive or.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    thanx PING I never though of !=

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    In some cases, if you aren't particularly careful, that method could bite you (although, it is a fine solution). Note the following:

    p xor q is equivalent to (p or q) and (not (p and q))

    Work out the truth tables, and you'll see.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 06:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 01:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21