Search code examples
booleanboolean-logicboolean-expressionboolean-operations

Boolean expression with four operands


How can I write a boolean expression which will be true if and only if there is one out of four operands is true? I need the most succinct possible way to write it.


Solution

  • Here's how I'd do it:

    ((A XOR B) XOR (C XOR D)) AND (NOT (A AND B)) AND (NOT (C AND D))
    

    The first part

    ((A XOR B) XOR (C XOR D)) 
    

    Works for all cases except three inputs being true, hence the second part.