Logic gates

Logic gates are the building blocks of nearly all digital electronics. There are seven types: and, or, not, nand, nor, xor and xnor. The output state of these logic gates depends on the state of the inputs. For example, the output of the and gate is only high when all inputs are high.

And gate

The output of the and gate is only high when all inputs are high. The output is low in all other situations.

And gate
A B Out
0 0 0
1 0 0
0 1 0
1 1 1

Or gate

The output of the or gate is high when at least one input is high. The output is only low when all inputs are low.

Or gate
A B Out
0 0 0
1 0 1
0 1 1
1 1 1

Not gate

The output of the not gate is high if the input is low, and output is low if the input is high. The not gate can only have one input.

Not gate
A Out
0 1
1 0

Nand gate (Not and)

The nand gate behaves the opposite of the and gate; The output is only low when all inputs are high.

Nand gate (Not and)
A B Out
0 0 1
1 0 1
0 1 1
1 1 0

Nor gate (Not or)

The nor gate behaves the opposite of the or gate; The output is only high if all inputs are low.

Nor gate (Not or)
A B Out
0 0 1
1 0 0
0 1 0
1 1 0

Xor gate (Exclusive or, eor)

The output of the xor gate is high when at least one, but not all inputs are high.

Xor gate (Exclusive or, eor)
A B Out
0 0 0
1 0 1
0 1 1
1 1 0

Xnor gate (Exclusive not or, enor)

The xnor gate behaves the opposite of the xor gate; The output is high if none or all inputs are high. The output is low in all other situations.

Xnor gate (Exclusive not or, enor)
A B Out
0 0 1
1 0 0
0 1 0
1 1 1

Example