The Three Ways of XOR
horia141.com
The Three Ways of XOR
1–10 of 69 posts
Re: The Three Ways of XOR
#2I guess the author never taught of != . The only thing to be careful with is that it doesn't implicitly convert arguments to boolean, so expressions like " != (flags & Flag)" will go wrong without an explicit conversion "bool(flags & Flag)" or equivalent expression like "((flags & Flag) != 0)".
And let's not forget about the friend, ==. I've more than once seen code like "(a && b) || (!a && !b)".
A similar interesting pattern many don't think of is "bool(a1) + ... + bool(aN) == M" (particularly with M==1) and instead we see unreadable monstrosities :)
Re: The Three Ways of XOR
#3> most programming languages don’t have an explicit “logical operator” for it I guess the author never taught of != . The only thing to be careful with is that it doesn't implicitly convert arguments to boolean, so expressions like " != (flags & Flag)" will go wrong without an explicit conversion "bool(flags & Flag)" or equivalent expression like "((flags & Flag) != 0)". And let's not forget about the friend, ==. I'v…
Re: The Three Ways of XOR
#4> most programming languages don’t have an explicit “logical operator” for it I guess the author never taught of != . The only thing to be careful with is that it doesn't implicitly convert arguments to boolean, so expressions like " != (flags & Flag)" will go wrong without an explicit conversion "bool(flags & Flag)" or equivalent expression like "((flags & Flag) != 0)". And let's not forget about the friend, ==. I'v…
Is "bool(a1) + ... + bool(aN) == M" not just "a1 || a2...||an"?
Re: The Three Ways of XOR
#5> most programming languages don’t have an explicit “logical operator” for it I guess the author never taught of != . The only thing to be careful with is that it doesn't implicitly convert arguments to boolean, so expressions like " != (flags & Flag)" will go wrong without an explicit conversion "bool(flags & Flag)" or equivalent expression like "((flags & Flag) != 0)". And let's not forget about the friend, ==. I'v…
Is "bool(a1) + ... + bool(aN) == M" not just "a1 || a2...||an"?
The latter is the same as "a1 + ... + an == 1 || a1 + ... + an == 2 || ... || a1 + ... + an == n".
Re: The Three Ways of XOR
#6Wonder when the current AI summer will come to an end...
Re: The Three Ways of XOR
#7Re: The Three Ways of XOR
#8Earlier quoted context omitted.
Is "bool(a1) + ... + bool(aN) == M" not just "a1 || a2...||an"?
No, it's true when exactly M are true. "a1 || a2 || ... || an" is true when at least one is true. The latter is the same as "a1 + ... + an == 1 || a1 + ... + an == 2 || ... || a1 + ... + an == n".
Re: The Three Ways of XOR
#9Re: The Three Ways of XOR
#10Earlier quoted context omitted.
No, it's true when exactly M are true. "a1 || a2 || ... || an" is true when at least one is true. The latter is the same as "a1 + ... + an == 1 || a1 + ... + an == 2 || ... || a1 + ... + an == n".
So your + operator implicitly casts booleans to an integer type, with false=0 and true=1?