3 Logic gate is a basic element of [logic circuits](logic_circuit.md), a simple device that implements a [Boolean function](bool.md), i.e. it takes a number of [binary](binary.md) (1 or 0) input values and transforms them into an output binary value. Logic gates are kind of "small boxes" that eat 1s and 0s and spit out other 1s and 0s. Strictly speaking a logic gate must implement a mathematical function, so e.g. [flip-flops](flip_flop.md) don't fall under logic gates because they have an internal state/[memory](memory.md).
5 Logic gates are to logic circuits kind of what [resistors](resistor.md), [transistors](transistor.md) etc. are for electronic circuits. They implement basic functions that in the realm of boolean logic are equivalents of addition, multiplication etc.
7 Behavior of logic gates is, just as with logic circuits, commonly expressed with so called [truth tables](truth_table.md), i.e. a tables that show the gate's output for any possible combination of inputs. But it can also be written as some kind of equation etc.
9 There are 2 possible logic gates with one input and one output:
11 - **[identity](identity.md) (buffer)**: Output equals the input. This doesn't have any function from the logic perspective but can e.g. be used as a placeholder or to introduce intentional delay in the physical circuit etc.
12 - **[NOT](not.md)**: Negates the input (0 to 1, 1 to 0).
14 There are 16 possible logic gates with two inputs and one output (logic table of 4 rows can have 2^4 possible output values), however only some of them are commonly used and have their own names. These are:
16 - **[OR](or.md)**: Gives 1 if at least one input is 1, otherwise 0.
17 - **[AND](and.md)**: Gives 1 if both inputs are 1, otherwise 0.
18 - **[XOR](xor.md) (exclusive OR)**: Gives 1 if inputs differ, otherwise 0.
19 - **[NOR](nor.md)**: Negation of OR.
20 - **[NAND](nand.md)**: Negation of AND.
21 - **[XNOR](xnor.md)**: Negative XOR (equality).
23 The truth table of these gates is as follows:
25 | x | y | x OR y | x AND y | x XOR y | x NOR y | x NAND y | x XNOR y |
26 |---|---|--------|---------|---------|---------|----------|----------|
27 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
28 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 |
29 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
30 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
34 ---\ ''-. ---\ ''-. ---| '. ---| '.
35 ) )--- ) )O-- | )--- | )O--
36 ---/__..-' ---/__..-' ---|_____.' ---|_____.'
39 --\\ ''-. --\\ ''-. |'. |'.
40 )) )--- )) )O-- ---| >--- ---| >O--
41 --//__..-' --//__..-' |.' |.'
42 XOR XNOR ' BUFFER ' NOT
46 ---|=> 1| ---| & | ---|= 1 | | 1 |
47 | |--- | |--- | |--- ---| |o--
48 ---|____| ---|____| ---|____| |____|
53 --|OR |-- --|AND|-- --|XOR|-- --|NOT|--
54 --|___| --|___| --|___| |___|
57 *symbols often used for logic gates*
59 Functions NAND and NOR are so called [functionally complete](functional_completeness.md) which means we can implement any other gate with only one of these gates. For example NOT(x) = NAND(x,x), AND(x,y) = NAND(NAND(x,y),NAND(x,y)), OR(x,y) = NAND(NAND(x,x),NAND(y,y)) etc. Similarly NOT(x) = NOR(x,x), OR(x,y) = NOR(NOR(x,y),NOR(x,y)) etc.
63 - [logic circuit](logic_circuit.md)
64 - [quantum gate](quantum_gate.md)