Show description
Digital Logic & Circuits: The Rad Guide
Digital Logic & Circuits: The Rad Guide
DIGITAL LOGIC 101
The Ultimate Guide to Logic Gates & Circuits
What's the Big Deal?
Welcome, future tech wizard! You're about to learn the secret language of computers. Everything your phone, laptop, or gaming console does—from browsing the web to running a game—boils down to incredibly simple decisions made billions of times per second. These decisions are handled by tiny electronic switches called logic gates. Master them, and you'll understand the very foundation of all digital technology. Let's dive in!
The Core Concepts: Binary
Computers don't understand words or numbers like we do. They only understand two states: ON and OFF. We represent these states using a system called binary.
1 represents ON (or HIGH, TRUE, POWER ON)
0 represents OFF (or LOW, FALSE, POWER OFF)
Logic gates are the components that take these binary inputs (0s and 1s) and produce a single binary output based on a specific rule.
1
ON / TRUE
0
OFF / FALSE
NOT Gate (The Inverter)
The NOT gate is the simplest of all. It takes one input and flips it. If you give it a 1, it outputs a 0. If you give it a 0, it outputs a 1. It's the rebel of the circuit world.
Truth Table
Input A
Output
0
1
1
0
Interactive Simulation
A
Q
AND Gate (The All-or-Nothing)
The AND gate is a strict one. It has two or more inputs and will only output a 1 if ALL of its inputs are 1. If even one input is 0, the output is 0.
Truth Table
Input A
Input B
Output
0
0
0
0
1
0
1
0
0
1
1
1
Interactive Simulation
A
B
Q
OR Gate (The Easy-Going One)
The OR gate is much more relaxed. It will output a 1 if ANY of its inputs are 1. It only outputs 0 if all inputs are 0.
Truth Table
Input A
Input B
Output
0
0
0
0
1
1
1
0
1
1
1
1
Interactive Simulation
A
B
Q
XOR Gate (The "One or the Other")
XOR stands for "Exclusive OR". It only outputs 1 if the inputs are DIFFERENT.…
Digital Logic & Circuits: The Rad Guide
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Logic & Circuits: The Rad Guide</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Inter:wght@400;600&display=swap" rel="stylesheet">
<style>
/* Custom styles for the dark, futuristic theme */
body {
background-color: #0a0e1a;
color: #c0c5ce;
font-family: 'Inter', sans-serif;
overflow-x: hidden;
}
h1, h2, h3 {
font-family: 'Orbitron', sans-serif;
color: #63b3ed; /* A nice, bright blue */
text-shadow: 0 0 5px rgba(99, 179, 237, 0.4);
}
.gate-container {
background-color: rgba(17, 24, 39, 0.8);
border: 1px solid #2b3a55;
backdrop-filter: blur(10px);
}
.truth-table {
width: 100%;
border-collapse: collapse;
}
.truth-table th, .truth-table td {
border: 1px solid #2b3a55;
padding: 0.75rem;
text-align: center;
}
.truth-table th {
background-color: #1e293b;
color: #63b3ed;
}
.truth-table code {
font-weight: 700;
font-size: 1.1rem;
}
/* Styles for the interactive SVG circuits */
.circuit-svg {
user-select: none;
}
.wire {
stroke: #374151; /* Dark gray for OFF state */
stroke-width: 4;
fill: none;
transition: stroke 0.3s ease;
}
.gate-shape {
stroke: #63b3ed;
stroke-width: 3;
fill: #111827;
transition: fill 0.3s ease;
}
.io-node {
cursor: pointer;
fill: #374151; /* OFF state */
stroke: #63b3ed;
stroke-width: 2;
transition: fill 0.3s ease;
}
.io-label {
font-family: 'Orbitron', sans-serif;
font-size: 18px;
fill: #c0c5ce;
pointer-events: none;
}
/* The 'ON' or 'ACTIVE' state for circuit elements */
.active .wire {
stroke: #38bdf8; /* Bright, glowing blue */
filter: drop-shadow(0 0 3px #38bdf8);
}
.active.io-node {
fill: #38bdf8;
filter: drop-shadow(0 0 4px #38bdf8);
}
/* Cool background effect */
.background-grid {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
background-image:
linear-gradient(rgba(23, 37, 62, 0.5) 1px, transparent 1px),
linear-gradient(90deg, rgba(23, 37, 62, 0.5) 1px, transparent 1px);
background-size: 30px 30px;
animation: pan-grid 60s linear infinite;
}
@keyframes pan-grid {
0% { background-position: 0 0; }
100% { background-position: 300px 300px; }
}
</style>
</head>
<body class="min-h-screen text-lg leading-relaxed">
<div class="background-grid"></div>
<main class="container mx-auto p-4 md:p-8">
<!-- Header -->
<header class="text-center my-12">
<h1 class="text-5xl md:text-7xl font-bold tracking-widest">DIGITAL LOGIC 101</h1>
<p class="text-xl text-gray-400 mt-4">The Ultimate Guide to Logic Gates & Circuits</p>
</header>
<!-- Introduction Section -->
<section class="gate-container rounded-xl p-6 md:p-8 my-8 text-center shadow-lg">
<h2 class="text-3xl mb-4">What's the Big Deal?</h2>
<p class="max-w-4xl mx-auto">
Welcome, future tech wizard! You're about to learn the secret language of computers. Everything your phone, laptop, or gaming console does—from browsing the web to running a game—boils down to incredibly simple decisions made billions of times per second. These decisions are handled by tiny electronic switches called <strong class="text-blue-300">logic gates</strong>. Master them, and you'll understand the very foundation of all digital technology. Let's dive in!
</p>
</section>
<!-- Core Concepts Section -->
<section class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h2 class="text-3xl mb-4">The Core Concepts: Binary</h2>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p>Computers don't understand words or numbers like we do. They only understand two states: ON and OFF. We represent these states using a system called <strong class="text-blue-300">binary</strong>.</p>
<ul class="list-disc list-inside mt-4 space-y-2">
<li><code class="bg-gray-900 px-2 py-1 rounded text-cyan-400 font-bold">1</code> represents <strong class="text-green-400">ON</strong> (or HIGH, TRUE, POWER ON)</li>
<li><code class="bg-gray-900 px-2 py-1 rounded text-red-400 font-bold">0</code> represents <strong class="text-gray-500">OFF</strong> (or LOW, FALSE, POWER OFF)</li>
</ul>
<p class="mt-4">Logic gates are the components that take these binary inputs (0s and 1s) and produce a single binary output based on a specific rule.</p>
</div>
<div class="flex justify-center items-center space-x-8">
<div class="text-center">
<span class="text-8xl font-bold text-green-400" style="text-shadow: 0 0 10px rgba(52, 211, 153, 0.5);">1</span>
<p class="text-2xl font-bold">ON / TRUE</p>
</div>
<div class="text-center">
<span class="text-8xl font-bold text-gray-600">0</span>
<p class="text-2xl font-bold">OFF / FALSE</p>
</div>
</div>
</div>
</section>
<!-- Logic Gates Start Here -->
<div id="gates-section">
<!-- NOT Gate -->
<section id="not-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-cyan-300">NOT Gate (The Inverter)</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">The NOT gate is the simplest of all. It takes one input and flips it. If you give it a 1, it outputs a 0. If you give it a 0, it outputs a 1. It's the rebel of the circuit world.</p>
<h4 class="text-xl font-bold mb-2 text-blue-300">Truth Table</h4>
<table class="truth-table">
<thead><tr><th>Input A</th><th>Output</th></tr></thead>
<tbody>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-green-400">1</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-red-400">0</code></td></tr>
</tbody>
</table>
</div>
<div class="flex flex-col items-center">
<h4 class="text-xl font-bold mb-2 text-blue-300">Interactive Simulation</h4>
<!-- Interactive SVG for NOT Gate -->
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="NOT">
<!-- Input A -->
<g class="input-a" data-state="0">
<path class="wire" d="M 20 75 H 100"></path>
<circle class="io-node input-node" cx="20" cy="75" r="15" data-input="A"></circle>
<text class="io-label" x="15" y="80">A</text>
</g>
<!-- Gate Shape -->
<path class="gate-shape" d="M 100 50 L 100 100 L 160 75 Z"></path>
<circle class="gate-shape" cx="170" cy="75" r="10" fill="#0a0e1a"></circle>
<!-- Output Q -->
<g class="output-q" data-state="1">
<path class="wire" d="M 180 75 H 280"></path>
<circle class="io-node output-node" cx="280" cy="75" r="15"></circle>
<text class="io-label" x="275" y="80">Q</text>
</g>
</svg>
</div>
</div>
</section>
<!-- AND Gate -->
<section id="and-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-cyan-300">AND Gate (The All-or-Nothing)</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">The AND gate is a strict one. It has two or more inputs and will only output a 1 if <strong class="text-blue-300">ALL</strong> of its inputs are 1. If even one input is 0, the output is 0.</p>
<h4 class="text-xl font-bold mb-2 text-blue-300">Truth Table</h4>
<table class="truth-table">
<thead><tr><th>Input A</th><th>Input B</th><th>Output</th></tr></thead>
<tbody>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td></tr>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-green-400">1</code></td><td><code class="text-red-400">0</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td></tr>
</tbody>
</table>
</div>
<div class="flex flex-col items-center">
<h4 class="text-xl font-bold mb-2 text-blue-300">Interactive Simulation</h4>
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="AND">
<!-- Input A -->
<g class="input-a" data-state="0">
<path class="wire" d="M 20 45 H 100"></path>
<circle class="io-node input-node" cx="20" cy="45" r="15" data-input="A"></circle>
<text class="io-label" x="15" y="50">A</text>
</g>
<!-- Input B -->
<g class="input-b" data-state="0">
<path class="wire" d="M 20 105 H 100"></path>
<circle class="io-node input-node" cx="20" cy="105" r="15" data-input="B"></circle>
<text class="io-label" x="15" y="110">B</text>
</g>
<!-- Gate Shape -->
<path class="gate-shape" d="M 100 30 L 100 120 L 140 120 C 170 120, 170 30, 140 30 Z"></path>
<!-- Output Q -->
<g class="output-q" data-state="0">
<path class="wire" d="M 170 75 H 280"></path>
<circle class="io-node output-node" cx="280" cy="75" r="15"></circle>
<text class="io-label" x="275" y="80">Q</text>
</g>
</svg>
</div>
</div>
</section>
<!-- OR Gate -->
<section id="or-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-cyan-300">OR Gate (The Easy-Going One)</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">The OR gate is much more relaxed. It will output a 1 if <strong class="text-blue-300">ANY</strong> of its inputs are 1. It only outputs 0 if all inputs are 0.</p>
<h4 class="text-xl font-bold mb-2 text-blue-300">Truth Table</h4>
<table class="truth-table">
<thead><tr><th>Input A</th><th>Input B</th><th>Output</th></tr></thead>
<tbody>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td></tr>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-red-400">0</code></td><td><code class="text-green-400">1</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td></tr>
</tbody>
</table>
</div>
<div class="flex flex-col items-center">
<h4 class="text-xl font-bold mb-2 text-blue-300">Interactive Simulation</h4>
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="OR">
<!-- Input A -->
<g class="input-a" data-state="0">
<path class="wire" d="M 20 45 H 80"></path>
<circle class="io-node input-node" cx="20" cy="45" r="15" data-input="A"></circle>
<text class="io-label" x="15" y="50">A</text>
</g>
<!-- Input B -->
<g class="input-b" data-state="0">
<path class="wire" d="M 20 105 H 80"></path>
<circle class="io-node input-node" cx="20" cy="105" r="15" data-input="B"></circle>
<text class="io-label" x="15" y="110">B</text>
</g>
<!-- Gate Shape -->
<path class="gate-shape" d="M 80 30 C 120 50, 120 100, 80 120 Q 110 75, 170 75 Q 110 75, 80 30 Z"></path>
<!-- Output Q -->
<g class="output-q" data-state="0">
<path class="wire" d="M 170 75 H 280"></path>
<circle class="io-node output-node" cx="280" cy="75" r="15"></circle>
<text class="io-label" x="275" y="80">Q</text>
</g>
</svg>
</div>
</div>
</section>
<!-- XOR Gate -->
<section id="xor-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-cyan-300">XOR Gate (The "One or the Other")</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">XOR stands for "Exclusive OR". It only outputs 1 if the inputs are <strong class="text-blue-300">DIFFERENT</strong>. If both inputs are the same (both 0 or both 1), it outputs 0.</p>
<h4 class="text-xl font-bold mb-2 text-blue-300">Truth Table</h4>
<table class="truth-table">
<thead><tr><th>Input A</th><th>Input B</th><th>Output</th></tr></thead>
<tbody>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td><td><code class="text-red-400">0</code></td></tr>
<tr><td><code class="text-red-400">0</code></td><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-red-400">0</code></td><td><code class="text-green-400">1</code></td></tr>
<tr><td><code class="text-green-400">1</code></td><td><code class="text-green-400">1</code></td><td><code class="text-red-400">0</code></td></tr>
</tbody>
</table>
</div>
<div class="flex flex-col items-center">
<h4 class="text-xl font-bold mb-2 text-blue-300">Interactive Simulation</h4>
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="XOR">
<!-- Input A -->
<g class="input-a" data-state="0">
<path class="wire" d="M 20 45 H 80"></path>
<circle class="io-node input-node" cx="20" cy="45" r="15" data-input="A"></circle>
<text class="io-label" x="15" y="50">A</text>
</g>
<!-- Input B -->
<g class="input-b" data-state="0">
<path class="wire" d="M 20 105 H 80"></path>
<circle class="io-node input-node" cx="20" cy="105" r="15" data-input="B"></circle>
<text class="io-label" x="15" y="110">B</text>
</g>
<!-- Gate Shape -->
<path class="gate-shape" d="M 90 30 C 130 50, 130 100, 90 120 Q 120 75, 180 75 Q 120 75, 90 30 Z"></path>
<path class="gate-shape" d="M 75 25 C 115 45, 115 105, 75 125" stroke-width="3" fill="none"></path>
<!-- Output Q -->
<g class="output-q" data-state="0">
<path class="wire" d="M 180 75 H 280"></path>
<circle class="io-node output-node" cx="280" cy="75" r="15"></circle>
<text class="io-label" x="275" y="80">Q</text>
</g>
</svg>
</div>
</div>
</section>
</div>
<!-- Footer -->
<footer class="text-center text-gray-500 my-12">
<p>Go build something amazing!</p>
</footer>
</main>
<script>
// JavaScript for Interactive Logic Gates
document.addEventListener('DOMContentLoaded', () => {
const gateSimulators = document.querySelectorAll('.circuit-svg');
gateSimulators.forEach(svg => {
const gateType = svg.dataset.gateType;
const inputNodes = svg.querySelectorAll('.input-node');
// Set initial states based on data attributes
updateGateVisuals(svg);
inputNodes.forEach(node => {
node.addEventListener('click', () => {
const inputGroup = node.closest('g');
const currentState = parseInt(inputGroup.dataset.state, 10);
// Toggle state between 0 and 1
inputGroup.dataset.state = 1 - currentState;
updateGateVisuals(svg);
});
});
});
});
function updateGateVisuals(svg) {
const gateType = svg.dataset.gateType;
// Get current input states
const inputAEl = svg.querySelector('.input-a');
const inputBEl = svg.querySelector('.input-b');
const stateA = inputAEl ? parseInt(inputAEl.dataset.state, 10) : null;
const stateB = inputBEl ? parseInt(inputBEl.dataset.state, 10) : null;
let outputState = 0;
// Calculate output based on gate type
switch (gateType) {
case 'NOT':
outputState = stateA === 0 ? 1 : 0;
break;
case 'AND':
outputState = (stateA === 1 && stateB === 1) ? 1 : 0;
break;
case 'OR':
outputState = (stateA === 1 || stateB === 1) ? 1 : 0;
break;
case 'XOR':
outputState = (stateA !== stateB) ? 1 : 0;
break;
}
// Update visuals for inputs
if (inputAEl) {
if (stateA === 1) inputAEl.classList.add('active');
else inputAEl.classList.remove('active');
}
if (inputBEl) {
if (stateB === 1) inputBEl.classList.add('active');
else inputBEl.classList.remove('active');
}
// Update visuals for output
const outputQEl = svg.querySelector('.output-q');
if (outputQEl) {
outputQEl.dataset.state = outputState;
if (outputState === 1) outputQEl.classList.add('active');
else outputQEl.classList.remove('active');
}
}
</script>
</body>
</html>