BI 3 Logic Gates
What are Logic Gates?
Logic gates are electronic devices that perform Boolean operations. They receive one or more binary inputs (0
or 1
) and produce a single binary output. These gates form the foundation of all digital systems, including computers, mobile devices, and other technologies.
Types
In digital circuits, the most common logic gates are:
- AND Gate: Produces
1
only when both inputs are1
. - OR Gate: Produces
1
when at least one input is1
. - NOT Gate: Inverts the input (turns
1
into0
and0
into1
). - NAND Gate: The inverse of the AND gate.
- NOR Gate: The inverse of the OR gate.
- XOR Gate: Produces
1
when the inputs are different. - XNOR Gate: Produces
1
when the inputs are the same.
Their symbols include:
Logic Gate | Symbol | Basic Operation | DeMorgan's Equivalent |
---|---|---|---|
AND | A ∧ B | True if both A and B are true | ¬(¬A ∨ ¬B) |
OR | A ∨ B | True if either A or B is true | ¬(¬A ∧ ¬B) |
NOT | ¬A | Flips true ↔ false | (no change) |
NAND | ¬(A ∧ B) | Opposite of AND | (NOT A) OR (NOT B) → ¬A ∨ ¬B |
NOR | ¬(A ∨ B) | Opposite of OR | (NOT A) AND (NOT B) → ¬A ∧ ¬B |
XOR (Exclusive OR) | A ⊕ B | True if only one is true | (A ∧ ¬B) ∨ (¬A ∧ B) |
XNOR (Exclusive NOR) | ¬(A ⊕ B) | True if both are same | (A ∧ B) ∨ (¬A ∧ ¬B) |
0
–> FALSE
1
–> TRUE
1. AND Gate (&&)
If inputs are the same, AND returns the same output. If both inputs are 1
, then the output returns 1
(true).
Else, it returns 0
(false).
A | B | Output (A AND B) |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Boolean Expression: A ⋅ B
Impact –> Authorization process (keycard AND PIN required)
2. OR Gate (||)
If at least one output is 1
,*OR returns 1
.
Else 0
.
A | B | Output (A OR B) |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Boolean Expression: A + B
Impact –> Automatic door activation (motion sensor OR button press)
3. NOT Gate (!A)
Inverts the input. If the input is 1
, NOT returns 0
, and vice versa.
A | Output (NOT A) |
---|---|
0 | 1 |
1 | 0 |
Boolean Expression: Ā
Impact –> Thermostat system (when temperature threshold is reached, NOT signals to turn off)
4. NAND & NOR Gates
- NAND (
NOT AND
): Inverts AND gate output. - NOR (
NOT OR
): Inverts OR gate output.
A | B | NAND (¬(A ⋅ B)) | NOR (¬(A + B)) |
---|---|---|---|
0 | 0 | 1 | 1 |
0 | 1 | 1 | 0 |
1 | 0 | 1 | 0 |
1 | 1 | 0 | 0 |
- NAND & NOR are universal gates - any circuit can be built using only NAND or only NOR gates.
Impact –> Self-driving cars (whether to break or steer from conditions)
5. XOR Gate (⊕)
The output is 1
(true) if inputs are different. If inputs are the same, XOR returns 0
(false).
A | B | Output (A XOR B) |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Boolean Expression: A ⊕ B
Impact –> Computer memory (whether data is the same or different)
6. XNOR Gate (⊙)
The XNOR (Exclusive NOR) gate is the opposite of XOR.
The output is 1
when both inputs are the same.
A | B | Output (A XNOR B) |
---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Boolean Expression: A ⊙ B = ĀB + A B̄ = ¬(A ⊕ B)
Impact –> Pattern recognition (evaluate similarities)
Popcorn Hack
What are methods of real-world purpose that using logic gates can implement? Explain deeper if using our listed impacts, explaining why this impact is helpful.
Popcorn Hack 2
A digital circuit receives three binary inputs: X, Y, and Z. The circuit outputs 1 if and only if X AND Y are both 1, OR Z is 1.
Which of the following expressions represents the circuit’s behavior?
A. (X AND Y) OR Z B. X AND (Y OR Z) C. (X OR Y) AND Z D. NOT(X AND Y) OR Z
Homework Hack: Authorization System
Task: Fill in the missing code necessary to implement a Python function that simulates a secure entry system using an AND gate.
Template:
def secure_entry_system(keycard, pin):
def AND(a, b):
return a & b # AND logic
return AND(keycard, pin)
# Test cases
print(secure_entry_system(1, 1)) # Expected Output: 1 (Access Granted)
print(secure_entry_system(0, 1)) # Expected Output: 0 (Access Denied)
The above is code for a secure entry system - using a keycard and a pin. You’ll notice that to have access into the system, you need to have both a keycard and a pin (And Gate). Your task is to add another variable (like voice authorization) that is required to have access into the building.
Answer
```python def secure_entry_system(keycard, pin, voice): def AND(a, b, c): return a & b & c # AND logic return AND(keycard, pin, voice) ```Homework Submission
Submit your popcorn and homework hacks here. There are also MCQ questions to test your acquired logic gates knowledge.