# Using XOR

• 10-11-2010, 05:01 AM
minime12358
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
• 10-11-2010, 05:05 AM
Zack
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:
Code:

```int count = 0; if (a) count++; if (b) count++; if (c) count++; if (d) count++; if (e) count++; if (count == 1) {     // .. }```
• 10-11-2010, 05:23 AM
minime12358
: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!