Re:The Three Ways of XOR
by kevinwang on Sunday February 12, 2017 @05:30PM
(#13631413)
Is "bool(a1) + ... + bool(aN) == M" not just "a1 || a2...||an"?
[ Parent
| on HN ]
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
by Ded7xSEoPKYNsDd on Sunday February 12, 2017 @06:01PM
(#13631649)
So your + operator implicitly casts booleans to an integer type, with false=0 and true=1?
What you are saying is the only way I can imagine to interpret what I wrote, if one assumes I was intending to make any sense.
By the way, in Python, bool is a subtype of int (i.e., instanceof(True,int) == True), and True + True == 2. C is the same, and in Javascript booleans are converted to integers for arithmetic operations.
> What you are saying is the only way I can imagine to interpret what I wrote
One might imagine it (without experience, or not thinking, of any particular programming language) as being a logical OR on Booleans - which in EE at least is frequently written '+'.
Re:The Three Ways of XOR
by simcop2387 on Sunday February 12, 2017 @06:18PM
(#13631765)
In c++, yes. Not every language will do that though.