
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

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) {
// ..
}

: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!