Practical Electronics/Logic
Ii In the sense of electronics, logic means that the circuit works using only two voltage levels  high and low (or on/off, true/false or 1/0). These voltage levels are sometimes called logic levels and digital circuits use only these logic levels to represent information.
Contents
Logic Gates[edit]
Input  Output 

A  Q 
0  1 
1  0 
Logic gates are devices that can combine multiple inputs at independent logic levels and come up with an output accordingly. There are many kinds of logic gates, and the distinction lies in that each kind processes the inputs differently, and may give different ouputs for the same inputs.
The way the logic gate processes different inputs is given in a truth table for that gate, which lists all the possible combinations of inputs next to their outputs. An example is given for a simple oneinput gate with the function of giving the opposite logic level at the output to the one at the input. The inputs are given on the left, and the outputs are on the right. Generally, the inputs are called A, B, C, etc., and the output is labelled Q. In this case, there are only two possible inputs, 1 or 0, but logic gates can have any number of inputs.
There are seven kinds of logic gates,each kind of logic gate has a circuit symbol associated with it. In fact, there are several conflicting standards defining the symbols for logic gates. The standard symbols are ANSI symbols, sometimes called the MIL symbols. These are the most distinctive and are widely used and recognised. It is recommended to use these symbols for basic logic cirucits, and this wikibook will use them to the exclusion of the others. It is better to use the IEC (rectangular) symbols for advanced logic designs, but this is at a higher level that this book. The comparison between the three symbol sets is given here.
Boolean Algebra[edit]
Boolean algebra is a way to mathematically express logical operations performed on data. There are symbols for the operations performed by each logic gate, and these are given in the relevant sections below. It uses several symbols that are not generally used anywhere else, and the use of these will be also be explained below. Boolean algebra can be used to represent several logical operations done at once, and this be explained in this section.
Each kind of gate has its own symbol used when writing the functions down, but ideally, only the symbols for NOT, AND, OR and XOR are used, to reduce confusion, and to ease simplification.
The 7 Basic Gates[edit]
NOT[edit]
A  Q 

¬A  
0  1 
1  0 
A NO gate or an inverter is the simplest kind of logic gate. Its function is to give the opposite output to its input  if it gets a high, it gives a low, and vice versa. This is equivalent to saying that the output is not the input.
The circuit symbol, left, for a NOT gate is a triangle with the point facing towards the output, and a circle at the output.
The boolean symbol for the NOT operator is either a line over the relevant input, or a "¬" symbol preceding it. Thus, the statement that the output, Q, is not the input, A, is either

 or
For instructions on how to write this in Wikitext or HTML, see here.
NOT gates can be implemented in a variety of ways. See the following for more information:
 4049  The standard CMOS inverter. This IC contains six independednt inverters.
 Alternatives to an inverter. This page details methods other than using a 4049 for achieving a logical NOT operation.
AND[edit]
A  B  Q 

AB  
0  0  0 
0  1  0 
1  0  0 
1  1  1 
An AND gate gives a high output only when both inputs are high. If one or more inputs are low, then the output is also low. This is equivalent to saying that the output is high when one input and the other one are high.
The circuit symbol, left, for an AND gate is a box with one rectangular end (inputs) and one semicircular end (output).
Boolean multiplication is equivalent to the AND function (see why here Thus, the AND gate can be represented by a multiplication dot · or just putting the two terms together.

 or .
For instructions on how to write this in Wikitext or HTML, see here
See the following for more information on the implementation of AND gates:
 4081  The standard CMOS AND gate. This IC contains four independent AND gates.
 Alternatives to an AND Gate. This page details methods other than using a 4081 for achieving a logical AND operation.
NAND[edit]
A  B  Q 

AB  
0  0  1 
0  1  1 
1  0  1 
1  1  0 
A NAND gate gives a low output only when both inputs are high. If one or more inputs is low, then the output is high. This is equivalent to saying that the output is NOT the output of an AND gate presented with the same inputs. This NOT AND combination is shortened to just NAND.
The circuit symbol, left, for an NAND gate is a box with one rectangular end (inputs) and one semicircular end (output). This output end has a small circle, denoting an inversion.
The boolean symbol for the NAND operator is a vertical line (the Sheffer Stroke). Thus, the NAND gate can be represented by the boolean statement
NAND can also be written as the negation (NOT) of the AND:

 or .
This is the prefered notation, as it is easier to see what is happening in terms of the basic functions.
See the following for more information on the implementation of AND gates:
 4011  The standard CMOS NAND gate. This IC contains four independent NAND gates.
 Alternatives to an NAND Gate. This page details methods other than using a 4011 for achieving a logical NAND operation.
NAND gates have the property that any other logic gate can be mode from just NAND gates. For the method of achieving this, see NAND Logic(NAND logic).
OR[edit]
A  B  Q 

A+B  
0  0  0 
0  1  1 
1  0  1 
1  1  1 
An OR gate gives a high output if any input is high. If all inputs are low, then the output is low. This is equivalent to saying that the output is high only when one OR the other OR both inputs are high.
The circuit symbol, left, for an OR gate is similar to that of an AND gate, but with a pointed end (ouptuts) and a concave end (inputs).
Boolean addition is eqivalent to the OR function (see why here Thus, the OR gate can be represented by a plus sign (+):
A Vshaped symbol can also be used, but it is not common and should not generally be used.
See the following for more information on the implementation of OR gates:
 4071  The standard CMOS OR gate. This IC contains four independent OR gates.
 Alternatives to an OR Gate. This page details methods other than using a 4071 for achieving a logical OR operation.
NOR[edit]
A  B  Q 

A⊥B  
0  0  1 
0  1  0 
1  0  0 
1  1  0 
A NOR gate gives a high output only if no inputs are high. If an input is high, then the output is low. This is equivalent to saying that the output is high only when when neither one NOR the other input is high. It is the opposite to an OR gate.
The circuit symbol, left, for a NOR gate is similar to that of an OR gate, but for the addition of a circle to denote the inversion from an OR gate.
NOR can also be written as the negation (NOT) of the OR:

 .
This is the preferred notation. Another symbol for the NOR operator is a symbol like "⊥", which can be used when the line over the top cannot easily be drawn (e.g. in normal text like this):
See the following for more information on the implementation of NOR gates:
 4001  The standard CMOS NOR gate. This IC contains four independent NOR gates.
 Alternatives to an NOR Gate. This page details methods other than using a 4001 for achieving a logical NOR operation.
NOR gates have the property that any other logic gate can be mode from just NOR gates. For the method of achieving this, see NOR Logic.
XOR[edit]
A  B  Q 

A≠B  
0  0  0 
0  1  1 
1  0  1 
1  1  0 
An XOR gate short for "exclusiveOR", gives a high output if one input is high and the other is low. If both inputs are the same, the output is low. This is equivalent to saying that the output is high only when one OR the other but not both inputs are high.
The circuit symbol, left, for an XOR gate is similar to that of an OR gate, but with a double line at the concave input end.
The boolean symbol for the XOR operator is a plussign in a circle or, because it only returns a high when the inputs are different,a notequalto sign (not generally used). Thus, the XOR gate can be represented by the boolean statements

 or
For instructions on how to write this in Wikitext or HTML, see /Practical Electronics/Help/Logic Symbols#XOR
See the following for more information on the implementation of XOR gates:
 4030  The standard CMOS XOR gate. This IC contains four independent XOR gates.
 Alternatives to an XOR Gate. This page details methods other than using a 4030 for achieving a logical XOR operation.
XNOR[edit]
A  B  Q 

A≡B  
0  0  1 
0  1  0 
1  0  0 
1  1  1 
An XNOR gate short for "exclusiveNOR", gives a high output if both outputs are the same  it is the opposite of the XOR gate.
The circuit symbol, left, for an XNOR gate is similar to that of an XOR gate, but it has a circle representing the inversion at the ouput.
XNOR is written as the negation of the XOR function:
As the XNOR function only returns a "one" when both inputs are the same, the boolean symbol for the XNOR operator is an equalvalentto sign (≡) sign (not equals) in normal text. Because this looks very much like an equals sign it is easily mistaken and should not be used where possible.
See the following for more information on the implementation of XNOR gates:
 4077  The standard CMOS XNOR gate. This IC contains four independent XNOR gates.
 Alternatives to an XNOR Gate. This page details methods other than using a 4077 for achieving a logical XNOR operation.
Uses of Logic Gates[edit]
Logic gates underpin most of digital electronics, (indeed the entire onboard computer in the Apollo spacecraft was made of NOR gates).
The most obvious uses is for simple control. Imagine designing a washing machine so that the water only turns on when the washing is loaded (logic1), the door is closed (logic1) but the clothes are not yet wet (logic0). This can be done by ANDing the first two conditions, and inverting the third. Now, AND these together, and you get a high only when all three conditions are satified.
Washing  Door  Wet Clothes  Washing AND Door  NOT Wet Clothes  Water (output) 

A  B  C  AB  ¬C  (AB)(¬C) 
0  0  0  0  1  0 
0  0  1  0  0  0 
0  1  0  0  1  0 
0  1  1  0  0  0 
1  0  0  0  1  0 
1  0  1  0  0  0 
1  1  0  1  1  1 
1  1  1  1  0  0 
By using just three logic gates (and, at most two ICs  one 4081 and one 4049), the problem has been solved.
However, logic gates are also used to make flipflops and other vital electronic components.
One convenient use of them is as transmission gates which allow a signal to pass only under certain conditions.