Teach: Logic Circuits and Logical Operations
Logic Circuits and Logical Operations
Inside the CPU, the brain of a computer, logic circuits work by combining 0s and 1s to perform calculations and make decisions. Even computers that seem complex are based on only three simple types of circuits. In this lesson, we will learn about the logical operations AND, OR, and NOT and how circuits made by combining them work.
Three Basic Logical Operations
In logical operations, inputs and outputs are represented by 0 (false) and 1 (true). The three basic operations are as follows.
AND (logical conjunction): The output is 1 only when both inputs are 1. It corresponds to "A and B."
OR (logical disjunction): The output is 1 when at least one input is 1. It corresponds to "A or B."
NOT (negation): It reverses the input. It outputs 1 for 0 and 0 for 1.
A table listing every combination of inputs and the corresponding outputs is called a truth table.
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
Familiar examples are that AND is like a circuit with two switches connected in series (both must be ON for the light to turn on), while OR is like a circuit with switches connected in parallel (the light turns on when either is ON).
XOR (Exclusive OR)
A representative operation made by combining the three basic operations is XOR (exclusive OR). XOR outputs 1 only when the inputs are different (0 and 1 → 1, 1 and 1 → 0). It represents "one or the other, but not both" and is essential to the addition circuits described below.
Adding with Logic Circuits — The Half Adder
In one-digit binary addition, "0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 10," the sum digit is the XOR output and the carry is the AND output. Therefore, combining one XOR circuit and one AND circuit creates a half adder that performs one-digit addition. Combining half adders further creates a full adder that can handle carries from the lower digit, completing a circuit that can add numbers of any length. CPU calculations are achieved through this accumulation of simple circuits.
- AND: "1 if both are 1"; OR: "1 if either is 1"; NOT: "reverse."
- A truth table organizes outputs for every input pattern. With two inputs, it has four rows.
- XOR is 1 when the inputs differ. Its difference from OR is that 1 + 1 gives 0.
- Half adder = XOR (sum) + AND (carry). Calculations can be achieved by combining simple circuits.
Practice Questions
- When A = 1 and B = 0, give the outputs of A AND B, A OR B, and A XOR B.
- When A = 1 and B = 1, give the output of NOT (A AND B).
- When calculating 1 + 1 with a half adder, what are the sum and carry?
Answers and Explanations
- Answer: AND = 0, OR = 1, XOR = 1
Explanation: AND is 0 because both inputs are not 1. OR is 1 because one input is 1. XOR is 1 because the inputs differ. - Answer: 0
Explanation: First, A AND B = 1. Reversing it with NOT gives 0. The negation of AND is called NAND, and it is the circuit most often used in actual IC design. - Answer: Sum = 0, carry = 1
Explanation: In binary, 1 + 1 = 10. The sum digit corresponds to XOR(1,1) = 0, and the carry corresponds to AND(1,1) = 1.
Previous and next lessons in this course
- Previous lesson: Teach: Binary Numbers and Information Quantity
- Next lesson: Teach: Algorithms and Flowcharts