1. Member Join Date
Jul 2010
Posts
21
Rep Power
0 Using XOR

Hi, I was using the XOR function in the following:
if(((numb(base,base)==1)^(numb(base,base)==1)^(numb(base,base)==1)^(numb(base,base)==1)^(numb(base,base)==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  Reply With Quote

2. 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.  Reply With Quote

3. Member Join Date
Jul 2010
Posts
21
Rep Power
0 :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!  Reply With Quote Posting Permissions

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