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 (i.e., they are commutative).


 * 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 (i.e., they are associative).


 * When an XOR gate is combined in this way, its output is on when an odd number of inputs is on. (Also known as "parity".)

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.