Now that you've been introduced to the binary system, let's explore how computers actually perform computations using bits!
To carry out operations with binary numbers, classical computers rely on logic gates. Logic gates are the building blocks of digital circuits: electronic components made from transistors and other hardware. They take one or more binary inputs (bits) and produce a single binary output based on a specific operation.
The following demonstration is an interactive illustration of how logic gates work within circuits. Experiment with different types of logic gates to discover how computers perform basic logical operations and form the foundation of computation!
Logic Gate Demonstration
AND Gate
The AND gate performs an AND operation on two inputs.
How it works:
The AND gate performs an operation on pairs of bits from two binary numbers. In each column, a "1" is only produced in the "Result" row if both digits on top are also 1. This can be visualized with the following logic:
- 0 AND 0 = 0
- 0 AND 1 = 0
- 1 AND 0 = 0
- 1 AND 1 = 1
For example, if the column labeled 0 had the number 0 in the "Input A" row, and the number 1 in the "Input B" row, it would produce a 0 in the "Result" row. If there is a 1 in both rows, then there will also be a 1 in the "Result" row. Enter in different numbers to observe this phenomenon!
OR Gate
The OR gate performs an OR operation on two inputs.
How it works:
The OR gate performs logical operations based on whether or not there is a 1 in two strings of binary. In each column, a "1" is only produced in the "Result" row if there is at least a single 1 on top. This can be visualized with the following logic:
- 0 OR 0 = 0
- 0 OR 1 = 1
- 1 OR 0 = 1
- 1 OR 1 = 1
For example, if the column labeled 0 had the number 0 in the "Input A" row, and the number 1 in the "Input B" row, it would produce a 1 in the "Result" row. If there is a 0 in both rows, then there will also be a 0 in the "Result" row. Enter in different numbers to observe this phenomenon!
XOR Gate
The XOR (Exclusive OR) gate performs an XOR operation on two inputs.
How it works:
The XOR gate performs logical operations based on whether or not there is a difference between each digit in two strings of binary. In each column, a "1" is only produced in the "Result" row if the digits on top are different. This can be visualized with the following logic:
- 0 XOR 0 = 0
- 0 XOR 1 = 1
- 1 XOR 0 = 1
- 1 XOR 1 = 0
For example, if the column labeled 0 had the number 0 in the "Input A" row, and the number 1 in the "Input B" row, it would produce a 1 in the "Result" row. If there is a 1 in both rows, then there will also be a 0 in the "Result" row. Enter in different numbers to observe this phenomenon!
Although the logic gates do not perform computations themselves, they are often employed within larger circuits to create systems that can perform basic operations!
For example, combining multiple AND gates with other electronic components allows the computer to perform multiplication! Also, combining multiple XOR and OR gates allows the computer to perform addition/subtraction, producing a numerical output!