Redstone circuits/Logic

A logic gate can be thought of as a simple device that will return a number of outputs, determined by the pattern of inputs and rules that the logic gate follows. For example, if both inputs in an AND gate are in the 'true'/'on'/'powered'/'1' state, then the gate will return 'true'/'on'/'powered'/'1'.

There are many different kinds of logic gate, each of which can be implemented with many different designs. Each design has various advantages and disadvantages, such as size, complexity, speed, maintenance overhead, or cost. The various sections will give many different designs for each gate type.

Concepts
The output of each logic circuit reflects the state of its inputs at all times (though possibly with some delay incurred by the circuit).


 * Swapping inputs


 * For most of these gates, you can swap A and B without changing the output.


 * Swapping the inputs of the IMPLIES gate will affect its output, and the NOT gate has only one input.


 * Stacking inputs


 * The AND, OR, and XOR gates can each be used in arrays to perform their operation on more than two inputs, by combining two inputs at a time, then combining the results with each other and/or other inputs. For these gates, the order in which the inputs are combined doesn't matter.


 * When an XOR gate is combined in this way, its output is on when an odd number of inputs is on.


 * Choosing a logic gate


 * When unsure which logic gate to use, try building a table like the one on the right but with just one row of outputs. List the known inputs coming in and the possible combinations of power, and for each combination write down what the output should be for the structure to work. Then compare that to the table on the right and see which gate matches the desired outputs.


 * If the the output needs to change when the input is stable, or needs to be remembered after the input has ended (things that logic gates can't do), you may also need to look at pulse circuits or memory circuits.

Logic gate
A logic gate is a basic logic circuit.

NOT Gate
A NOT Gate (aka "inverter") turns on if its input is off.

OR Gate
An OR Gate turns on if either input is on.

NOR Gate
A NOR Gate turns on if both inputs are off.

AND Gate
An AND Gate turns on if both inputs are on.

NAND Gate
A NAND Gate turns on if either input is off.

XOR Gate
An XOR Gate turns on if the inputs are different from each other (one on, the other off).

XNOR Gate
An XNOR Gate turns on if both inputs are the same (both on, or both off).

IMPLIES Gate
An IMPLIES Gate turns on if both inputs are on, or if the first input is off.