Why there are only 6 logical gates

in #computerscience4 years ago (edited)

I have recently been learning very basic computer science things. Logical gates specifically. Logical gates are actually extremely easy, I just never got around to learning what they were, other than "what computers are made of". Logical gates are mechanical parts that output either 1 or 0, true or false, for two inputs of either 1 or 0 each. The total number of combinations of inputs to outputs, is actually very few, and for this reason there are only 6 logical gates.

The alternatives are, output 1 when both inputs are 0 ("NOR"). Or, when both inputs are 1 ("AND"). Or, when both inputs are either both 0, or both 1 ("XNOR"). Or, when both inputs are different, one is 0 and the other is 1 ("XOR"). Or, when both inputs are either different, or both are 1 ("OR"). Or, when both inputs are either different, or both are 0 ("NAND").

That is all logical gates, since it is all combinations of two bit input to one bit output, if both sides are interchangeable so that a 1 and 0 input and a 0 and 1 input give the same result. Try it yourself. Only six gates in total can exist.

Then, there is also a "NOT" gate, that only takes one input, and inverts it. Input 1 outputs 0, and input 0 outputs 1. But it differs from the others so much that I count it separately here.

These basic computations on two bit inputs to one bit output can be combined to create one type of gate from another gate. The NOR gate, is for example the inverse of the OR gate (inverting the output), NAND the inverse of the AND, and XNOR the inverse of the XOR. An OR can also easily be created from a NAND (that is in turn created from an AND) by inverting the inputs. And same with creating AND from OR. And XOR can be created from an OR gate, that removes the AND possible input (both inputs are passed through OR, and AND with inverted output, a NAND, and both outputs are passed through an AND. )

These basic computation units can also easily be combined to do things like addition, equal-to comparison, or not-equal-to comparison. To do addition, a XOR gate outputs the first bit, and, an AND gate outputs the second bit. So that 1 + 1 in binary outputs 10 in base-2, or 2 in decimal. To compare if two bits are equal to one another, pass them through an "XNOR" gate, that outputs 1 if both inputs are both 0 or if they are both 1. To compare bit sequences longer than 1, pair all results and pass them through AND gates, then pair the results of that and pass them through AND gates, until you get a single output. And, to compare if two bits are not equal to one another, pass them through a "XOR" gate, that only outputs 1 if both inputs are different.

From this, you can build all computers that have ever been built and all computers that currently exist. Exactly how, I don't know. I want to learn that eventually.