1. Home
  2. Explore
  3. Computer Science
  4. Logic Gates and Circuits

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Logic Gates and Circuits

Logic Gates and Combinational Circuits

Binary inputs and outputs

A logic gate applies a rule to one or more binary inputs and produces a binary output. Each input and output is a bit: either 000 or 111. Gates can be connected so that one gate’s output becomes another gate’s input; this creates a combinational circuit whose final output depends on its inputs.

The four gates covered here are AND, OR, exclusive OR (XOR), and NOT.


The four basic gates

AND

An AND gate outputs 111 only when both inputs are 111. In every other case, it outputs 000.

For inputs AAA and BBB:

  • A=0A=0A=0, B=0B=0B=0 → output 000

  • A=0A=0A=0, B=1B=1B=1 → output 000

  • A=1A=1A=1, B=0B=0B=0 → output 000

  • A=1A=1A=1, B=1B=1B=1 → output 111

Symbolically, its output is A∧BA \land BA∧B.

OR

An OR gate outputs 111 when at least one input is 111. It outputs 000 only when both inputs are 000. This is an inclusive OR: two inputs of 111 still produce 111.

  • A=0A=0A=0, B=0B=0B=0 → output 000

  • A=0A=0A=0, B=1B=1B=1 → output 111

  • A=1A=1A=1, B=0B=0B=0 → output 111

  • A=1A=1A=1, B=1B=1B=1 → output 111

Symbolically, its output is A∨BA \lor BA∨B.

Exclusive OR (XOR)

An XOR gate outputs 111 when exactly one of its two inputs is 1.Ifbothinputsarethesame,theoutputis1. If both inputs are the same, the output is1.Ifbothinputsarethesame,theoutputis0$.

  • A=0A=0A=0, B=0B=0B=0 → output 000

  • A=0A=0A=0, B=1B=1B=1 → output 111

  • A=1A=1A=1, B=0B=0B=0 → output 111

  • A=1A=1A=1, B=1B=1B=1 → output 000

Symbolically, its output is A⊕BA \oplus BA⊕B. XOR resembles OR, except that the input pair (1,1)(1,1)(1,1) produces 000 rather than 111.

NOT

A NOT gate, also called an inverter, takes one input and flips it:

  • Input 000 → output 111

  • Input 111 → output 000

Symbolically, the output is ¬A\lnot A¬A.

Key distinction: AND requires both inputs to be 111; OR requires at least one; XOR requires exactly one; NOT reverses a single input.


Reading and drawing gate diagrams

Logic gates are represented by symbols with input wires and an output wire. The descriptions below refer to common ANSI-style symbols; conventions can vary, but the logic performed by each gate stays the same.

  • AND: Typically drawn with a flat input side and a rounded output side. It has two inputs and one output.

  • OR: Typically has a curved input side and a pointed, curved output side. It has two inputs and one output.

  • XOR: Resembles an OR gate with an extra curved line near the input side. It has two inputs and one output.

  • NOT: Typically drawn as a triangle with a small circle, or “bubble,” at its output. It has one input and one output. The bubble indicates inversion.

Wires carry bits between gates. A gate’s output can feed one or more later gates, allowing gates to be connected in stages.


Combining gates into a circuit

A circuit can be evaluated by working from the input wires toward the final output. Each gate performs its operation on the bits arriving at its inputs, and its output is then passed to the next gate.

Consider a circuit with eight inputs, grouped as four pairs:

  1. The first pair goes into an AND gate.

  2. The second pair goes into an XOR gate.

  3. The third pair goes into an OR gate.

  4. The fourth pair goes into an AND gate.

  5. The outputs of the first AND and the XOR feed another AND gate.

  6. The outputs of the OR and the fourth AND feed another OR gate.

  7. Those two intermediate outputs feed an XOR gate.

  8. The XOR output feeds a NOT gate, producing the final result.

If the inputs are a,b,c,d,e,f,g,ha,b,c,d,e,f,g,ha,b,c,d,e,f,g,h, the circuit can be expressed as

¬(((a∧b)∧(c⊕d))⊕((e∨f)∨(g∧h)))\lnot\left(\left((a \land b) \land (c \oplus d)\right) \oplus \left((e \lor f) \lor (g \land h)\right)\right)¬(((a∧b)∧(c⊕d))⊕((e∨f)∨(g∧h)))

The nested operations show the circuit’s hierarchy: the lower-level gates are evaluated first, and their results are then combined by higher-level gates.

Evaluating example inputs

With all inputs set to 000, each of the four bottom gates outputs 000. The next AND produces 000, and the next OR also produces 000. Their XOR produces 000, which the final NOT flips to 111. Thus, the final output is 111.

With all inputs set to 111, the four bottom gates output 111, 000, 111, and 111, respectively. The intermediate AND produces 000, while the intermediate OR produces 111. Their XOR produces 111, and the final NOT flips it to 000. Thus, the final output is 000.

For another example, use the inputs (1,0,1,0,1,0,1,0)(1,0,1,0,1,0,1,0)(1,0,1,0,1,0,1,0):

  • The bottom outputs are 000 from AND, 111 from XOR, 111 from OR, and 000 from AND.

  • The intermediate AND receives 000 and 111, so it outputs 000.

  • The intermediate OR receives 111 and 000, so it outputs 111.

  • The next XOR receives 000 and 111, so it outputs 111.

  • The final NOT flips that result to 000.


Using truth tables to evaluate circuits

A truth table lists input combinations and the corresponding outputs. It can show the behavior of an individual gate or of a whole circuit.

For a two-input gate, there are four possible input pairs: (0,0)(0,0)(0,0), (0,1)(0,1)(0,1), (1,0)(1,0)(1,0), and (1,1)(1,1)(1,1). A truth table for an eight-input circuit must cover 28=2562^8=25628=256 possible input combinations.

For the NOT gate, there are only two possible inputs, 000 and 111. Its truth table records that each input is inverted.

A bottom-up method

Truth tables and circuit diagrams both work best when calculations proceed from the inputs toward the final output:

  1. List the circuit’s input bits.

  2. Calculate the outputs of the gates connected directly to those inputs.

  3. Use those outputs as inputs to the next layer of gates.

  4. Continue layer by layer until reaching the final gate.

  5. Record the final output for that input combination.

For the eight-input circuit, the four bottom-gate outputs are calculated first. The two intermediate outputs come next, followed by the XOR and then the NOT.

Keeping intermediate results in separate columns makes the work easier to check. For example, a table might track the outputs of the bottom AND, XOR, OR, and AND gates, followed by the outputs of the intermediate AND and OR, then the final XOR and NOT. This avoids repeatedly recalculating earlier gates.

Truth tables for intermediate gates

A gate’s two-input rule can be reused wherever that gate appears. For example, once the four possible AND input pairs and their outputs are recorded, the same rule applies to every AND gate in the circuit. The same is true for OR and XOR. A separate two-case table describes NOT.

For a small circuit, it can be practical to compute each input combination by hand. As the number of inputs grows, the number of combinations grows exponentially: a circuit with nnn binary inputs has 2n2^n2n possible input combinations. Breaking the circuit into layers helps organize the calculation, while a complete truth table records the final output for every possible input.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent