Show description
Digital Logic 201: The Intermediate Guide
Digital Logic 201: The Intermediate Guide
DIGITAL LOGIC 201
The Intermediate Guide to Universal Gates
The Universal Gates
You've mastered the basics. Now, let's get to the really powerful stuff. In the world of digital logic, some gates are more special than others. The NAND and NOR gates are known as "universal gates." This means you can build ANY other logic gate (AND, OR, NOT, etc.) using only NAND gates or only NOR gates. This is huge for circuit design, making them incredibly efficient and important.
NAND Gate (The "Not AND")
The NAND gate is the inverse of an AND gate. It outputs a 0 only when ALL of its inputs are 1. In all other cases, it outputs a 1. Think of it as an AND gate with a NOT gate attached to its output.
Truth Table
Input A
Input B
Output
0
0
1
0
1
1
1
0
1
1
0
0
Interactive Simulation
A
B
Q
NOR Gate (The "Not OR")
Similarly, the NOR gate is the inverse of an OR gate. It will output a 1 only if ALL of its inputs are 0. If any input is a 1, the output is 0. It's an OR gate with an inverter on the end.
Truth Table
Input A
Input B
Output
0
0
1
0
1
0
1
0
0
1
1
0
Interactive Simulation
A
B
Q
XNOR Gate (The Equality Checker)
The XNOR (Exclusive NOR) gate is the inverse of XOR. It outputs a 1 only if its inputs are the SAME (both 0 or both 1). This makes it a great "equality gate" to check if two values are identical.
Truth Table
Input A
Input B
Output
0
0
1
0
1
0
1
0
0
1
1
1
Interactive Simulation
A
B
Q
You're well on your way to becoming a circuit master!
Digital Logic 201: The Intermediate 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 201: The Intermediate 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 - GREEN edition */
body {
background-color: #0a0e1a;
color: #c0c5ce;
font-family: 'Inter', sans-serif;
overflow-x: hidden;
}
h1, h2, h3 {
font-family: 'Orbitron', sans-serif;
color: #4ade80; /* Swapped to a bright green */
text-shadow: 0 0 5px rgba(74, 222, 128, 0.4);
}
.gate-container {
background-color: rgba(17, 24, 39, 0.8);
border: 1px solid #14532d; /* Dark green border */
backdrop-filter: blur(10px);
}
.truth-table {
width: 100%;
border-collapse: collapse;
}
.truth-table th, .truth-table td {
border: 1px solid #14532d; /* Dark green border */
padding: 0.75rem;
text-align: center;
}
.truth-table th {
background-color: #052e16; /* Darker green */
color: #4ade80;
}
.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: #4ade80; /* Green stroke */
stroke-width: 3;
fill: #111827;
transition: fill 0.3s ease;
}
.io-node {
cursor: pointer;
fill: #374151; /* OFF state */
stroke: #4ade80; /* Green stroke */
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: #22c55e; /* Bright, glowing green */
filter: drop-shadow(0 0 3px #22c55e);
}
.active.io-node {
fill: #22c55e;
filter: drop-shadow(0 0 4px #22c55e);
}
/* Cool background effect - GREEN edition */
.background-grid {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
background-image:
linear-gradient(rgba(22, 101, 52, 0.4) 1px, transparent 1px),
linear-gradient(90deg, rgba(22, 101, 52, 0.4) 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 201</h1>
<p class="text-xl text-gray-400 mt-4">The Intermediate Guide to Universal Gates</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">The Universal Gates</h2>
<p class="max-w-4xl mx-auto">
You've mastered the basics. Now, let's get to the really powerful stuff. In the world of digital logic, some gates are more special than others. The <strong class="text-green-300">NAND</strong> and <strong class="text-green-300">NOR</strong> gates are known as "universal gates." This means you can build ANY other logic gate (AND, OR, NOT, etc.) using only NAND gates or only NOR gates. This is huge for circuit design, making them incredibly efficient and important.
</p>
</section>
<!-- Logic Gates Start Here -->
<div id="gates-section">
<!-- NAND Gate -->
<section id="nand-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-emerald-300">NAND Gate (The "Not AND")</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">The NAND gate is the inverse of an AND gate. It outputs a 0 only when <strong class="text-green-300">ALL</strong> of its inputs are 1. In all other cases, it outputs a 1. Think of it as an AND gate with a NOT gate attached to its output.</p>
<h4 class="text-xl font-bold mb-2 text-green-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-green-400">1</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-red-400">0</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-green-300">Interactive Simulation</h4>
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="NAND">
<!-- Inputs -->
<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"></circle><text class="io-label" x="15" y="50">A</text></g>
<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"></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>
<circle class="gate-shape" cx="180" cy="75" r="10" fill="#0a0e1a"></circle>
<!-- Output -->
<g class="output-q" data-state="1"><path class="wire" d="M 190 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>
<!-- NOR Gate -->
<section id="nor-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-emerald-300">NOR Gate (The "Not OR")</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">Similarly, the NOR gate is the inverse of an OR gate. It will output a 1 only if <strong class="text-green-300">ALL</strong> of its inputs are 0. If any input is a 1, the output is 0. It's an OR gate with an inverter on the end.</p>
<h4 class="text-xl font-bold mb-2 text-green-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-green-400">1</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-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-green-300">Interactive Simulation</h4>
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="NOR">
<!-- Inputs -->
<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"></circle><text class="io-label" x="15" y="50">A</text></g>
<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"></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>
<circle class="gate-shape" cx="180" cy="75" r="10" fill="#0a0e1a"></circle>
<!-- Output -->
<g class="output-q" data-state="1"><path class="wire" d="M 190 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>
<!-- XNOR Gate -->
<section id="xnor-gate" class="gate-container rounded-xl p-6 md:p-8 my-8 shadow-lg">
<h3 class="text-4xl mb-4 text-emerald-300">XNOR Gate (The Equality Checker)</h3>
<div class="grid md:grid-cols-2 gap-8 items-center">
<div>
<p class="mb-4">The XNOR (Exclusive NOR) gate is the inverse of XOR. It outputs a 1 only if its inputs are the <strong class="text-green-300">SAME</strong> (both 0 or both 1). This makes it a great "equality gate" to check if two values are identical.</p>
<h4 class="text-xl font-bold mb-2 text-green-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-green-400">1</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-green-300">Interactive Simulation</h4>
<svg class="circuit-svg w-full max-w-sm" viewBox="0 0 300 150" data-gate-type="XNOR">
<!-- Inputs -->
<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"></circle><text class="io-label" x="15" y="50">A</text></g>
<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"></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>
<circle class="gate-shape" cx="190" cy="75" r="10" fill="#0a0e1a"></circle>
<!-- Output -->
<g class="output-q" data-state="1"><path class="wire" d="M 200 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>You're well on your way to becoming a circuit master!</p>
</footer>
</main>
<script>
document.addEventListener('DOMContentLoaded', () => {
const gateSimulators = document.querySelectorAll('.circuit-svg');
gateSimulators.forEach(svg => {
const inputNodes = svg.querySelectorAll('.input-node');
updateGateVisuals(svg);
inputNodes.forEach(node => {
node.addEventListener('click', () => {
const inputGroup = node.closest('g');
const currentState = parseInt(inputGroup.dataset.state, 10);
inputGroup.dataset.state = 1 - currentState;
updateGateVisuals(svg);
});
});
});
});
function updateGateVisuals(svg) {
const gateType = svg.dataset.gateType;
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;
// Logic calculations including new intermediate gates
switch (gateType) {
// NOTE: Basic gates from lesson 101 could be added here for a comprehensive file
case 'NAND':
outputState = (stateA === 1 && stateB === 1) ? 0 : 1;
break;
case 'NOR':
outputState = (stateA === 1 || stateB === 1) ? 0 : 1;
break;
case 'XNOR':
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>