# How do I get the NOT, NAND, NOR and XNOR logic gates to work?

The Contraptions Workshop DLC introduced a range of “Advanced switches”. Playing around with these, I found the AND, OR, and XOR gates to work exactly as expected, but not the NOT, NAND, NOR and XNOR gates. Here’s a fairly long explanation of what I’ve tried to get them to work:

This was my first attempt at using a NAND gate (which should be transmitting power unless both inputs are turned on):

Reading up, I discovered that the N- gates “only transmit power if their inputs are connected directly to the output of other logic gates.”

My next attempt, which I expected to work based on the information above, was to have an AND gate feeding into the NOT gate as such:

All logic gates require power, and their inputs and outputs can actually be in one of three possible states, demonstrated in the following table…

State  Description
(0) -> No Connection to Power
(1) => Connected to Power, Enabled (True)
(2) ~> Connected to Power, Disabled (False)

The Gotcha: (2) states only travel one connection and only certain devices can output a (2) state. For this reason, logic gates need to be directly connected to what is producing your ‘Powered but Disabled’ output.

Since all logic gates require power, AT LEAST ONE input is REQUIRED to always be either (1) or (2). You can tell if a logic gate has power by the small orange light on the top left of the device. A NOR Gate (Not Or) for example, will work when the inputs are [0,2] or [2,0] or [2,2] but not [0,0] as it would be unpowered.

Logic gates work by checking the last device’s output. This is contrary to how you might expect power to behave as flowing or propagating from one connection to the next. Since only certain devices can produce a (2) state, (ie, other logic gates), in most cases this means you’ll need to directly connect your input to another logic gate’s output when you need a Disabled/False input.

An easy way to remember this information is;

• Power propagates
• Logic checks the last connection

Example One:

A NAND Gate gives a powered output when both its inputs are Disabled (False). Here, both inputs are connected to a switch which is off, which produces no power. Since there is no power to the logic gate, it can’t produce the expected result, which should be powered.

Power Source (1) => Switch, Off (0) -> In 1. NAND Gate (0) => Light (0)
Power Source (1) => Switch, Off (0) -> In 2. ^

Example Two:

If we swap one of the two switches from the first example with a NOT Gate, the input light on the logic gate will still be unlit, but is actually in state (2), where it is powered, but disabled. The NAND Gate now gives us the expected powered output.

Power Source (1) => Switch, Off (0) -> In 1. NAND Gate (1) => Light (1)
Power Source (1) => NOT Gate    (2) ~> In 2. ^

Example Three:

A light connected directly to a NOT Gate won’t turn on. But it will if it’s connected to the output of a NOR Gate, where the inputs are coming from powered NOT Gates. This circuit will still work even if you disconnect one of the inputs, but as with Example One, if both inputs are removed or replaced with Switches that are set to off, the NOR Gate will no longer have power, and thus, neither will the light.

Power Source (1) => NOT Gate    (2) ~> In 1. NOR Gate (1) => Light (1)
Power Source (1) => NOT Gate    (2) ~> In 2. ^

Example Four & Five:

Two NOT Gates in series will produce power as expected.

Power Source (1) => NOT Gate (2) ~> NOT Gate (1) => Light (1)

However, if a conduit is placed between the two gates, the second NOT Gate will be checking what the input is connected to and finding it is (0), as a Power Conduit cannot produce a “Powered, Disabled” (2) state.

Power Source (1) => NOT Gate (2) ~> Conduit (0) -> NOT Gate (0) => Light (0)

With the above considered, if you aren’t using negated gates (N-anything), you probably won’t need to worry about keeping all your gates powered all the time. However, probably the most common case people are going to run into, is when they want two switches that will trigger a change in the output state when one is flicked. Logic dictates this can be accomplished with an XNOR Gate. (Equivalent to an XOR Gate followed by a NOT Gate)

An XNOR Gate’s logic/truth table follows:

Input 1     0   0   1   1
Input 2     0   1   0   1
-------------------------
Output      1   0   0   1

You may already see the problem here; the fourth result works as expected, but in-game if you used switches that were turned off to try create the first result, the gate will have no power.

Power Source (1) => Switch, Off (0) -> In 1. XNOR Gate (0) -> Light (0)
Power Source (1) => Switch, Off (0) -> In 2. ^

We can solve this by placing AND Gates between each switch and the XNOR Gate’s inputs, with one of the two AND Gate’s inputs permanently connected to a power source…

Power Source (1) => Switch, Off (0) -> In 1. AND Gate (2) ~> In 1. XNOR Gate (1) => Light (1)
Power Source (1) => ............... => In 2. ^                     ^
Power Source (1) => ............... => In 1. AND Gate (2) ~> In 2. ^
Power Source (1) => Switch, Off (0) -> In 2. ^

Now we have a pair of two-way switches that will activate the final output when both are on or off. Enjoy. 🙂

ADDENDUM: Practically the same result can be achieved with an XOR Gate by itself, with the caveat that output is true when the inputs don’t match, and inputs of [0,0] would of course result in the gate being unpowered. This isn’t an issue for a simple door or light, but may cause problems in more complex circuits. AND Gates on the inputs would of course correct this. The final example used an XNOR Gate as a demonstration of a situation where powering the output is necessary, and is not necessarily the optimal solution.