Skip to the content.

Logic Gates

Images lesson w/ homeworks

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.

Popcorn Hack

Question:
What are methods of real-world purpose that using logic gates can implement?
Answer:
Logic gates are used in real-world systems like:

  • Authorization systems: (AND gate) requiring keycard AND PIN to allow access ensures high security.
  • Automatic doors: (OR gate) activating if motion sensor OR button press detects a user, improving accessibility.
  • Thermostats: (NOT gate) turning systems off when reaching a temperature limit prevents overheating.
  • Self-driving cars: (NAND/NOR gates) combining multiple conditions like obstacle presence and speed for safe driving decisions.
  • Memory Checking: (XOR gate) detecting changes in stored data to prevent corruption.

These impacts make systems smarter, safer, and more reliable.


Popcorn Hack 2

Question:
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.

Answer:
Correct expression:
A. (X AND Y) OR Z


Homework Hack: Authorization System

Task:
Expand the secure entry system to also require voice authorization.

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)

def secure_entry_system(keycard, pin, voice):
    """Grant access only if all three credentials are present (1)."""
    def AND(a, b, c):
        return a & b & c  # 3-input AND logic

    return AND(keycard, pin, voice)


# Test cases
print(secure_entry_system(1, 1, 1))  # Expected: 1 (Access Granted)
print(secure_entry_system(1, 1, 0))  # Expected: 0 (Access Denied)
print(secure_entry_system(1, 0, 1))  # Expected: 0 (Access Denied)
print(secure_entry_system(0, 1, 1))  # Expected: 0 (Access Denied)