I need to do an xor conditional between 3 values, ie i need one of the three values to be true but not more than one and not none.
I thought i could use the xor ^ operator for this but its not working as expected.
I expected that this would return false but it doesnt. (true ^ true ^ true)
all other combinations seem to work as i expected.
When looking at the docs for the xor operator they only talk about comparing 2 values and i cant find anything on doing this for 3 or more values online.
Can anyone shed any light or suggest a simple way of doing this?
For 3-input XOR gates, we can have the HIGH input when odd numbers of inputs are at HIGH level. So the 3-input OR gate is called as “Odd functioned OR gate”.
If both of an XOR gate's inputs are false, or if both of its inputs are true, then the output of the XOR gate is false. If an XOR gate has more than two inputs, then its behavior depends on its implementation. In the vast majority of cases, an XOR gate will output true if an odd number of its inputs is true.
One way would be to convert the Boolean values to an integer, add the results, and compare to 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With