Results 1 to 3 of 3
Thread: Using XOR
- 10-11-2010, 05:01 AM #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[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 #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.
- 10-11-2010, 05:23 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 21
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks