Results 1 to 3 of 3

Thread: Using XOR

  1. #1
    minime12358 is offline Member
    Join Date
    Jul 2010
    Posts
    21
    Rep Power
    0

    Default Using XOR

    Hi, I was using the XOR function in the following:
    if(((numb(base,base[0])==1)^(numb(base,base[1])==1)^(numb(base,base[2])==1)^(numb(base,base[3])==1)^(numb(base,base[4])==1)))

    It is supposed to return false if more or less then 1 of the booleans are false. It is not working. I get hte following booleans:
    true false true true false
    but still, the if statement returns true :confused:
    Any help would be great, im really stuck on this

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Break it down:

    ((((true ^ false) ^ true) ^ true) ^ false)

    Since true ^ false == true,
    (((true ^ true) ^ true) ^ false)

    Next, true ^ true == false,
    ((false ^ true) ^ false)

    Then, false ^ true == true,
    (true ^ false)

    Again, true ^ false == true,
    true

    Does that make sense? Are you familiar with the function of XOR?

    Perhaps an easier way to detect if one statement is true, you could do something like this:
    Java Code:
    int count = 0;
    if (a) count++;
    if (b) count++;
    if (c) count++;
    if (d) count++;
    if (e) count++;
    if (count == 1) {
         // ..
    }
    Last edited by Zack; 10-11-2010 at 05:11 AM.

  3. #3
    minime12358 is offline Member
    Join Date
    Jul 2010
    Posts
    21
    Rep Power
    0

    Default

    :D Thanks! I know how XOR works, but I for some reason was thinking that the falses would just magically disappear :) . I ended up just doing a for loop for what you said, and that works great. My poker checker is complete!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •