Search code examples
logicternary

Simulate output with 3 cases


Physically is possible to simulate such situation on a board, using electronic components. I got 2 inputs A and B , with 3 possible values for each one (-1,0,1). My final aim is to achieve this following truth table

     A |  B | result
    –1 | –1 | +1
    –1 | +1 |  0
     0 |  0 |  0
     0 | +1 | +1
    +1 | –1 |  0
    +1 |  0 | +1
    +1 | +1 | -1

Solution

  • In pseudo code:

    if (A equals B)
        result = A * -1
    else
        result = A + B