Show description
Digital Systems Guide - Binary & Logic Fundamentals
Digital Systems Guide - Binary & Logic Fundamentals
DIGITAL SYSTEMSFUNDAMENTALS
BINARY • HEXADECIMAL • LOGIC
█ PLAYER 1 START █
LEVEL SELECT
Binary Basics
Number Conversions
Unsigned Arithmetic
Signed Binary
Hexadecimal
Truth Tables
Interactive Calculators
BINARY NUMBER SYSTEM
binary is the language of computers. every piece of data, from your favorite game to this webpage, is ultimately represented as a sequence of 1s and 0s.
WHY BINARY?
computers use binary because transistors (the building blocks of processors) have two states: ON (1) and OFF (0). it's like a light switch - either on or off, true or false, 1 or 0.
BINARY PLACE VALUES
just like decimal uses powers of 10, binary uses powers of 2:
Position: 7 6 5 4 3 2 1 0
Power: 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Value: 128 64 32 16 8 4 2 1
Example: 1010 1101
↓↓↓↓ ↓↓↓↓
128 + 32 + 8 + 4 + 1 = 173
EXAMPLE: CONVERT 10 0110 1101 TO DECIMAL
1 0 0 1 1 0 1 1 0 1
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
512 + 0 + 0 +128 + 64 + 0 + 16 + 8 + 0 + 1
= 512 + 128 + 64 + 16 + 8 + 1
= 729
PRO TIP: only add the place values where there's a 1. ignore positions with 0.
NUMBER SYSTEM CONVERSIONS
DECIMAL TO BINARY
to convert from decimal to binary, repeatedly divide by 2 and track the remainders:
EXAMPLE: CONVERT 73 TO 12-BIT BINARY
73 ÷ 2 = 36 remainder 1 ← LSB (least significant bit)
36 ÷ 2 = 18 remainder 0
18 ÷ 2 = 9 remainder 0
9 ÷ 2 = 4 remainder 1
4 ÷ 2 = 2 remainder 0
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 ← MSB (most significant bit)
Read from bottom to top: 1001001
Pad to 12 bits: 0000 0100 1001
EXAMPLE: CONVERT 127 TO 12-BIT BINARY
127 ÷ 2 = 63 remainder 1
63 ÷ 2 = 31 remainder 1
31 ÷ 2 = 15 remainder 1
15 ÷ 2 = 7 remainder 1
7 ÷ 2 = 3 remainder 1
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Result: 1111111
Pad to 12 bits: 0000 0111 1111
BINARY TO DECIMAL
0000 1111 0000
= 128 + 64 + 32 + 16
= 240
1100 1100 1100
= 2048 + 1024 + 128
+ 64 + 8 + 4
= 3276
UNSIGNED BINARY ARITHMETIC
unsigned binary numbers represent only positive values.…
Digital Systems Guide - Binary & Logic Fundamentals
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Systems Guide - Binary & Logic Fundamentals</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary-dark: #0f0f1e;
--secondary-dark: #1a1a2e;
--accent-cyan: #00ffff;
--accent-pink: #ff00ff;
--accent-yellow: #ffff00;
--accent-green: #00ff00;
--text-light: #e0e0e0;
--text-dim: #808080;
--border-color: #00ffff;
--shadow-glow: rgba(0, 255, 255, 0.5);
}
body {
font-family: 'Press Start 2P', cursive;
background: var(--primary-dark);
color: var(--text-light);
line-height: 1.8;
font-size: 10px;
overflow-x: hidden;
position: relative;
}
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background:
repeating-linear-gradient(
0deg,
rgba(0, 255, 255, 0.03) 0px,
transparent 1px,
transparent 2px,
rgba(0, 255, 255, 0.03) 3px
);
pointer-events: none;
z-index: 1000;
animation: scanlines 8s linear infinite;
}
@keyframes scanlines {
0% { transform: translateY(0); }
100% { transform: translateY(10px); }
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
@keyframes glow {
0%, 100% { box-shadow: 0 0 5px var(--shadow-glow); }
50% { box-shadow: 0 0 20px var(--shadow-glow); }
}
@keyframes blink {
0%, 49% { opacity: 1; }
50%, 100% { opacity: 0; }
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
position: relative;
z-index: 1;
}
header {
text-align: center;
padding: 40px 20px;
border: 4px solid var(--border-color);
background: var(--secondary-dark);
margin-bottom: 40px;
position: relative;
box-shadow: 0 0 20px var(--shadow-glow);
animation: glow 2s ease-in-out infinite;
}
header::before,
header::after {
content: '▲';
position: absolute;
color: var(--accent-cyan);
font-size: 20px;
animation: float 2s ease-in-out infinite;
}
header::before {
top: 10px;
left: 10px;
}
header::after {
bottom: 10px;
right: 10px;
content: '▼';
}
h1 {
font-size: 24px;
color: var(--accent-cyan);
text-shadow: 3px 3px 0 var(--accent-pink);
margin-bottom: 20px;
letter-spacing: 2px;
}
.subtitle {
font-size: 10px;
color: var(--accent-yellow);
margin-top: 10px;
}
.blink {
animation: blink 1s step-start infinite;
}
nav {
background: var(--secondary-dark);
border: 3px solid var(--accent-green);
padding: 20px;
margin-bottom: 30px;
position: sticky;
top: 10px;
z-index: 100;
}
nav h2 {
font-size: 12px;
color: var(--accent-green);
margin-bottom: 15px;
}
nav ul {
list-style: none;
}
nav li {
margin: 10px 0;
}
nav a {
color: var(--text-light);
text-decoration: none;
display: inline-block;
padding: 5px;
transition: all 0.3s;
}
nav a:hover {
color: var(--accent-cyan);
transform: translateX(10px);
text-shadow: 2px 2px 0 var(--accent-pink);
}
nav a::before {
content: '► ';
color: var(--accent-yellow);
}
section {
background: var(--secondary-dark);
border: 3px solid var(--border-color);
padding: 30px;
margin-bottom: 40px;
position: relative;
}
section::before {
content: attr(data-level);
position: absolute;
top: -15px;
left: 20px;
background: var(--primary-dark);
padding: 5px 15px;
color: var(--accent-yellow);
border: 2px solid var(--accent-yellow);
font-size: 8px;
}
h2 {
font-size: 16px;
color: var(--accent-pink);
margin-bottom: 20px;
text-shadow: 2px 2px 0 var(--accent-cyan);
}
h3 {
font-size: 12px;
color: var(--accent-yellow);
margin: 25px 0 15px;
}
p {
margin-bottom: 15px;
font-size: 10px;
line-height: 2;
}
.concept-box {
background: var(--primary-dark);
border: 2px solid var(--accent-green);
padding: 20px;
margin: 20px 0;
}
.concept-box h4 {
color: var(--accent-green);
font-size: 11px;
margin-bottom: 10px;
}
.example {
background: var(--primary-dark);
border-left: 4px solid var(--accent-cyan);
padding: 15px;
margin: 15px 0;
font-family: 'Courier New', monospace;
}
.example-title {
color: var(--accent-cyan);
font-family: 'Press Start 2P', cursive;
font-size: 9px;
margin-bottom: 10px;
}
.code-block {
background: #000;
border: 2px solid var(--accent-pink);
padding: 15px;
margin: 15px 0;
font-family: 'Courier New', monospace;
color: var(--accent-green);
overflow-x: auto;
white-space: pre;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-family: 'Courier New', monospace;
font-size: 9px;
}
th {
background: var(--primary-dark);
color: var(--accent-yellow);
border: 2px solid var(--accent-yellow);
padding: 10px;
font-family: 'Press Start 2P', cursive;
font-size: 8px;
}
td {
border: 1px solid var(--border-color);
padding: 10px;
text-align: center;
}
tr:nth-child(even) {
background: rgba(0, 255, 255, 0.05);
}
tr:hover {
background: rgba(255, 0, 255, 0.1);
}
.highlight {
color: var(--accent-yellow);
font-weight: bold;
}
.warning {
background: rgba(255, 0, 255, 0.1);
border: 2px solid var(--accent-pink);
padding: 15px;
margin: 15px 0;
}
.warning::before {
content: '⚠ WARNING ⚠';
display: block;
color: var(--accent-pink);
font-size: 9px;
margin-bottom: 10px;
}
.success {
background: rgba(0, 255, 0, 0.1);
border: 2px solid var(--accent-green);
padding: 15px;
margin: 15px 0;
}
.success::before {
content: '✓ SUCCESS';
display: block;
color: var(--accent-green);
font-size: 9px;
margin-bottom: 10px;
}
.info {
background: rgba(0, 255, 255, 0.1);
border: 2px solid var(--accent-cyan);
padding: 15px;
margin: 15px 0;
}
.info::before {
content: 'ℹ INFO';
display: block;
color: var(--accent-cyan);
font-size: 9px;
margin-bottom: 10px;
}
.calculator {
background: var(--primary-dark);
border: 3px solid var(--accent-yellow);
padding: 20px;
margin: 20px 0;
}
.calculator h4 {
color: var(--accent-yellow);
font-size: 11px;
margin-bottom: 15px;
}
input, select, button {
font-family: 'Press Start 2P', cursive;
font-size: 10px;
padding: 10px;
margin: 5px 0;
border: 2px solid var(--border-color);
background: var(--secondary-dark);
color: var(--text-light);
}
button {
cursor: pointer;
border: 3px solid var(--accent-green);
background: var(--primary-dark);
color: var(--accent-green);
padding: 12px 20px;
transition: all 0.3s;
}
button:hover {
background: var(--accent-green);
color: var(--primary-dark);
box-shadow: 0 0 15px var(--accent-green);
transform: scale(1.05);
}
button:active {
transform: scale(0.95);
}
input:focus, select:focus {
outline: none;
border-color: var(--accent-cyan);
box-shadow: 0 0 10px var(--shadow-glow);
}
.result {
background: var(--secondary-dark);
border: 2px solid var(--accent-cyan);
padding: 15px;
margin-top: 15px;
font-family: 'Courier New', monospace;
min-height: 50px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.card {
background: var(--primary-dark);
border: 2px solid var(--border-color);
padding: 20px;
}
.card h4 {
color: var(--accent-cyan);
font-size: 10px;
margin-bottom: 15px;
}
footer {
text-align: center;
padding: 30px;
border-top: 3px solid var(--border-color);
margin-top: 50px;
font-size: 8px;
color: var(--text-dim);
}
.pixel-corner {
position: absolute;
width: 20px;
height: 20px;
}
.pixel-corner.top-left {
top: -2px;
left: -2px;
border-top: 4px solid var(--accent-yellow);
border-left: 4px solid var(--accent-yellow);
}
.pixel-corner.top-right {
top: -2px;
right: -2px;
border-top: 4px solid var(--accent-yellow);
border-right: 4px solid var(--accent-yellow);
}
.pixel-corner.bottom-left {
bottom: -2px;
left: -2px;
border-bottom: 4px solid var(--accent-yellow);
border-left: 4px solid var(--accent-yellow);
}
.pixel-corner.bottom-right {
bottom: -2px;
right: -2px;
border-bottom: 4px solid var(--accent-yellow);
border-right: 4px solid var(--accent-yellow);
}
@media (max-width: 768px) {
body { font-size: 8px; }
h1 { font-size: 18px; }
h2 { font-size: 14px; }
h3 { font-size: 10px; }
.grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>DIGITAL SYSTEMS<br>FUNDAMENTALS</h1>
<p class="subtitle">BINARY • HEXADECIMAL • LOGIC</p>
<p class="subtitle"><span class="blink">█</span> PLAYER 1 START <span class="blink">█</span></p>
</header>
<nav>
<h2>LEVEL SELECT</h2>
<ul>
<li><a href="#binary-basics">Binary Basics</a></li>
<li><a href="#conversions">Number Conversions</a></li>
<li><a href="#unsigned">Unsigned Arithmetic</a></li>
<li><a href="#signed">Signed Binary</a></li>
<li><a href="#hex">Hexadecimal</a></li>
<li><a href="#truth-tables">Truth Tables</a></li>
<li><a href="#calculators">Interactive Calculators</a></li>
</ul>
</nav>
<section id="binary-basics" data-level="LEVEL 1">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>BINARY NUMBER SYSTEM</h2>
<p>binary is the language of computers. every piece of data, from your favorite game to this webpage, is ultimately represented as a sequence of 1s and 0s.</p>
<div class="concept-box">
<h4>WHY BINARY?</h4>
<p>computers use binary because transistors (the building blocks of processors) have two states: ON (1) and OFF (0). it's like a light switch - either on or off, true or false, 1 or 0.</p>
</div>
<h3>BINARY PLACE VALUES</h3>
<p>just like decimal uses powers of 10, binary uses powers of 2:</p>
<div class="code-block">Position: 7 6 5 4 3 2 1 0
Power: 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Value: 128 64 32 16 8 4 2 1
Example: 1010 1101
↓↓↓↓ ↓↓↓↓
128 + 32 + 8 + 4 + 1 = 173</div>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 10 0110 1101 TO DECIMAL</div>
<div class="code-block"> 1 0 0 1 1 0 1 1 0 1
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
512 + 0 + 0 +128 + 64 + 0 + 16 + 8 + 0 + 1
= 512 + 128 + 64 + 16 + 8 + 1
= 729</div>
</div>
<div class="info">
<p><span class="highlight">PRO TIP:</span> only add the place values where there's a 1. ignore positions with 0.</p>
</div>
</section>
<section id="conversions" data-level="LEVEL 2">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>NUMBER SYSTEM CONVERSIONS</h2>
<h3>DECIMAL TO BINARY</h3>
<p>to convert from decimal to binary, repeatedly divide by 2 and track the remainders:</p>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 73 TO 12-BIT BINARY</div>
<div class="code-block">73 ÷ 2 = 36 remainder 1 ← LSB (least significant bit)
36 ÷ 2 = 18 remainder 0
18 ÷ 2 = 9 remainder 0
9 ÷ 2 = 4 remainder 1
4 ÷ 2 = 2 remainder 0
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 ← MSB (most significant bit)
Read from bottom to top: 1001001
Pad to 12 bits: 0000 0100 1001</div>
</div>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 127 TO 12-BIT BINARY</div>
<div class="code-block">127 ÷ 2 = 63 remainder 1
63 ÷ 2 = 31 remainder 1
31 ÷ 2 = 15 remainder 1
15 ÷ 2 = 7 remainder 1
7 ÷ 2 = 3 remainder 1
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Result: 1111111
Pad to 12 bits: 0000 0111 1111</div>
</div>
<h3>BINARY TO DECIMAL</h3>
<div class="grid">
<div class="card">
<h4>0000 1111 0000</h4>
<div class="code-block">= 128 + 64 + 32 + 16
= 240</div>
</div>
<div class="card">
<h4>1100 1100 1100</h4>
<div class="code-block">= 2048 + 1024 + 128
+ 64 + 8 + 4
= 3276</div>
</div>
</div>
</section>
<section id="unsigned" data-level="LEVEL 3">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>UNSIGNED BINARY ARITHMETIC</h2>
<p>unsigned binary numbers represent only positive values. the range for n bits is 0 to 2ⁿ - 1.</p>
<div class="concept-box">
<h4>6-BIT UNSIGNED RANGE</h4>
<p>with 6 bits, you can represent: 0 to 63 (2⁶ - 1 = 64 - 1 = 63)</p>
</div>
<h3>BINARY ADDITION</h3>
<p>binary addition works just like decimal, but with carries at 2 instead of 10:</p>
<div class="code-block">Rules:
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 (0 with carry of 1)</div>
<div class="example">
<div class="example-title">EXAMPLE: 000011 + 001100 (3 + 12)</div>
<div class="code-block"> 000011 (3)
+ 001100 (12)
------
001111 (15)
NO OVERFLOW - result fits in 6 bits</div>
</div>
<div class="example">
<div class="example-title">EXAMPLE: 010100 + 101101 (20 + 45)</div>
<div class="code-block"> 1111 (carries)
010100 (20)
+ 101101 (45)
------
1000001 (65)
OVERFLOW! - result needs 7 bits
In 6-bit storage: 000001 (only keeps rightmost 6 bits)</div>
</div>
<div class="warning">
<p><span class="highlight">OVERFLOW DETECTION:</span> overflow occurs when the result exceeds the maximum value that can be stored. for 6-bit unsigned, any result > 63 causes overflow. look for a carry out of the leftmost bit.</p>
</div>
</section>
<section id="signed" data-level="LEVEL 4">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>SIGNED BINARY (TWO'S COMPLEMENT)</h2>
<p>signed binary uses two's complement representation to handle both positive and negative numbers. the leftmost bit is the sign bit: 0 = positive, 1 = negative.</p>
<div class="concept-box">
<h4>6-BIT SIGNED RANGE</h4>
<p>-32 to +31 (from -2⁵ to 2⁵ - 1)</p>
<p>positive: 000000 to 011111 (0 to 31)</p>
<p>negative: 100000 to 111111 (-32 to -1)</p>
</div>
<h3>CONVERTING TO TWO'S COMPLEMENT</h3>
<p>to represent a negative number:</p>
<div class="code-block">1. Start with positive binary representation
2. Invert all bits (0→1, 1→0)
3. Add 1</div>
<div class="example">
<div class="example-title">EXAMPLE: STORE +15 IN 6-BIT SIGNED</div>
<div class="code-block">15 in binary: 001111
Positive number: just use binary representation
Result: 001111</div>
</div>
<div class="example">
<div class="example-title">EXAMPLE: STORE -15 IN 6-BIT SIGNED</div>
<div class="code-block">Step 1: +15 = 001111
Step 2: Invert = 110000
Step 3: Add 1 = 110001
Result: 110001 represents -15</div>
</div>
<h3>CONVERTING FROM TWO'S COMPLEMENT</h3>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 011111 TO DECIMAL</div>
<div class="code-block">Starts with 0 → positive
011111 = 16 + 8 + 4 + 2 + 1 = 31
Result: +31</div>
</div>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 111001 TO DECIMAL</div>
<div class="code-block">Starts with 1 → negative
Step 1: Invert bits: 000110
Step 2: Add 1: 000111 = 7
Result: -7</div>
</div>
<h3>SIGNED ARITHMETIC</h3>
<div class="example">
<div class="example-title">EXAMPLE: 110101 + 001111</div>
<div class="code-block">110101 = -11 (negative, so convert: invert→001010, add 1→001011 = 11)
001111 = +15
110101 (-11)
+ 001111 (+15)
------
000100 (+4)
Result: +4, NO OVERFLOW</div>
</div>
<div class="info">
<p><span class="highlight">SIGNED OVERFLOW:</span> overflow in signed arithmetic occurs when:</p>
<p>• adding two positive numbers gives a negative result</p>
<p>• adding two negative numbers gives a positive result</p>
<p>• different signs CANNOT cause overflow</p>
</div>
</section>
<section id="hex" data-level="LEVEL 5">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>HEXADECIMAL NUMBER SYSTEM</h2>
<p>hexadecimal (base 16) is a compact way to represent binary. each hex digit represents exactly 4 binary bits.</p>
<div class="code-block">HEX DECIMAL BINARY
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111</div>
<h3>BINARY TO HEX</h3>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 10110100000101₂ TO HEX</div>
<div class="code-block">Step 1: Group into sets of 4 bits (from right)
0010 1101 0000 0101
Step 2: Convert each group
0010 = 2
1101 = D
0000 = 0
0101 = 5
Result: 2D05</div>
</div>
<h3>DECIMAL TO HEX</h3>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 791₁₀ TO HEX</div>
<div class="code-block">791 ÷ 16 = 49 remainder 7
49 ÷ 16 = 3 remainder 1
3 ÷ 16 = 0 remainder 3
Read from bottom up: 317₁₆</div>
</div>
<h3>HEX TO DECIMAL</h3>
<div class="example">
<div class="example-title">EXAMPLE: CONVERT 3FF₁₆ TO DECIMAL</div>
<div class="code-block">3FF₁₆ = (3 × 16²) + (15 × 16¹) + (15 × 16⁰)
= (3 × 256) + (15 × 16) + (15 × 1)
= 768 + 240 + 15
= 1023</div>
</div>
<div class="success">
<p><span class="highlight">WHY USE HEX?</span> hex is much more compact than binary. the 16-bit binary number 1111111111111111 is just FFFF in hex!</p>
</div>
</section>
<section id="truth-tables" data-level="LEVEL 6">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>TRUTH TABLES & DIGITAL LOGIC</h2>
<p>truth tables enumerate all possible input combinations and their corresponding outputs. they're fundamental to understanding digital circuits and logic design.</p>
<h3>BASIC CONCEPT</h3>
<div class="concept-box">
<h4>TRUTH TABLE RULES</h4>
<p>• n inputs produce 2ⁿ rows</p>
<p>• every row must have a defined output (0 or 1)</p>
<p>• systematically list all binary combinations</p>
<p>• outputs determined by logical conditions</p>
</div>
<h3>EXAMPLE PROBLEM 1: COMPARISON LOGIC</h3>
<p><span class="highlight">specification:</span> four inputs (a,b,c,d). first two (a,b) represent a number 1-3. second two (c,d) represent another number 1-3. output y=1 if first > second OR second = first + 2.</p>
<div class="example">
<div class="example-title">ENCODING SCHEME</div>
<div class="code-block">ab or cd:
00 = invalid (0 not used)
01 = 1
10 = 2
11 = 3</div>
</div>
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>first</th>
<th>second</th>
<th>condition</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>-</td><td>-</td><td>invalid</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>1</td><td>-</td><td>1</td><td>invalid</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>1</td><td>0</td><td>-</td><td>2</td><td>invalid</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>1</td><td>1</td><td>-</td><td>3</td><td>invalid</td><td>0</td></tr>
<tr><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>-</td><td>invalid</td><td>0</td></tr>
<tr><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1 = 1</td><td class="highlight">0</td></tr>
<tr><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td><td>2</td><td>1 < 2</td><td class="highlight">0</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>3</td><td>3 = 1+2</td><td class="highlight">1</td></tr>
<tr><td>1</td><td>0</td><td>0</td><td>0</td><td>2</td><td>-</td><td>invalid</td><td>0</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>1</td><td>0</td><td>0</td><td>1</td><td>2</td><td>1</td><td>2 > 1</td><td class="highlight">1</td></tr>
<tr><td>1</td><td>0</td><td>1</td><td>0</td><td>2</td><td>2</td><td>2 = 2</td><td class="highlight">0</td></tr>
<tr><td>1</td><td>0</td><td>1</td><td>1</td><td>2</td><td>3</td><td>2 < 3</td><td class="highlight">0</td></tr>
<tr><td>1</td><td>1</td><td>0</td><td>0</td><td>3</td><td>-</td><td>invalid</td><td>0</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>1</td><td>1</td><td>0</td><td>1</td><td>3</td><td>1</td><td>3 > 1</td><td class="highlight">1</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>1</td><td>1</td><td>1</td><td>0</td><td>3</td><td>2</td><td>3 > 2</td><td class="highlight">1</td></tr>
<tr><td>1</td><td>1</td><td>1</td><td>1</td><td>3</td><td>3</td><td>3 = 3</td><td class="highlight">0</td></tr>
</tbody>
</table>
<h3>EXAMPLE PROBLEM 2: PROXIMITY CHECK</h3>
<p><span class="highlight">specification:</span> four inputs (a,b,c,d). first two represent 0-2, second two represent 0-2 (3 not used). output y=1 if numbers don't differ by more than 1.</p>
<div class="example">
<div class="example-title">ENCODING SCHEME</div>
<div class="code-block">ab or cd:
00 = 0
01 = 1
10 = 2
11 = invalid (3 not used)</div>
</div>
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>first</th>
<th>second</th>
<th>|diff|</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td class="highlight">1</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td><td class="highlight">1</td></tr>
<tr><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>2</td><td>2</td><td class="highlight">0</td></tr>
<tr><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>-</td><td>-</td><td>0</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td class="highlight">1</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td><td>0</td><td class="highlight">1</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td><td>2</td><td>1</td><td class="highlight">1</td></tr>
<tr><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>-</td><td>-</td><td>0</td></tr>
<tr><td>1</td><td>0</td><td>0</td><td>0</td><td>2</td><td>0</td><td>2</td><td class="highlight">0</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>1</td><td>0</td><td>0</td><td>1</td><td>2</td><td>1</td><td>1</td><td class="highlight">1</td></tr>
<tr style="background: rgba(0, 255, 0, 0.2);"><td>1</td><td>0</td><td>1</td><td>0</td><td>2</td><td>2</td><td>0</td><td class="highlight">1</td></tr>
<tr><td>1</td><td>0</td><td>1</td><td>1</td><td>2</td><td>-</td><td>-</td><td>0</td></tr>
<tr><td>1</td><td>1</td><td>0</td><td>0</td><td>-</td><td>0</td><td>-</td><td>0</td></tr>
<tr><td>1</td><td>1</td><td>0</td><td>1</td><td>-</td><td>1</td><td>-</td><td>0</td></tr>
<tr><td>1</td><td>1</td><td>1</td><td>0</td><td>-</td><td>2</td><td>-</td><td>0</td></tr>
<tr><td>1</td><td>1</td><td>1</td><td>1</td><td>-</td><td>-</td><td>-</td><td>0</td></tr>
</tbody>
</table>
<div class="info">
<p><span class="highlight">TRUTH TABLE STRATEGY:</span></p>
<p>1. understand the input encoding</p>
<p>2. list all 2ⁿ combinations systematically</p>
<p>3. decode inputs to actual values</p>
<p>4. apply logical conditions</p>
<p>5. assign output based on conditions</p>
<p>6. mark invalid/unused combinations</p>
</div>
</section>
<section id="calculators" data-level="BONUS">
<div class="pixel-corner top-left"></div>
<div class="pixel-corner top-right"></div>
<div class="pixel-corner bottom-left"></div>
<div class="pixel-corner bottom-right"></div>
<h2>INTERACTIVE CALCULATORS</h2>
<div class="calculator">
<h4>BINARY TO DECIMAL CONVERTER</h4>
<input type="text" id="binInput" placeholder="Enter binary (e.g., 10110101)" style="width: 100%; margin-bottom: 10px;">
<button onclick="convertBinToDec()">CONVERT</button>
<div class="result" id="binResult"></div>
</div>
<div class="calculator">
<h4>DECIMAL TO BINARY CONVERTER</h4>
<input type="number" id="decInput" placeholder="Enter decimal number" style="width: 100%; margin-bottom: 10px;">
<input type="number" id="bitWidth" placeholder="Bit width (e.g., 12)" value="12" style="width: 100%; margin-bottom: 10px;">
<button onclick="convertDecToBin()">CONVERT</button>
<div class="result" id="decResult"></div>
</div>
<div class="calculator">
<h4>HEX CONVERTER</h4>
<input type="text" id="hexInput" placeholder="Enter hex (e.g., 2D05)" style="width: 100%; margin-bottom: 10px;">
<button onclick="hexToDec()">HEX → DECIMAL</button>
<button onclick="hexToBin()">HEX → BINARY</button>
<div class="result" id="hexResult"></div>
</div>
<div class="calculator">
<h4>TWO'S COMPLEMENT CONVERTER</h4>
<input type="number" id="twosInput" placeholder="Enter decimal (e.g., -15)" style="width: 100%; margin-bottom: 10px;">
<input type="number" id="twosBits" placeholder="Bit width (e.g., 6)" value="6" style="width: 100%; margin-bottom: 10px;">
<button onclick="convertTwos()">CONVERT</button>
<div class="result" id="twosResult"></div>
</div>
<div class="calculator">
<h4>BINARY ADDER (6-BIT UNSIGNED)</h4>
<input type="text" id="addA" placeholder="First 6-bit number" style="width: 100%; margin-bottom: 10px;">
<input type="text" id="addB" placeholder="Second 6-bit number" style="width: 100%; margin-bottom: 10px;">
<button onclick="addBinary()">ADD</button>
<div class="result" id="addResult"></div>
</div>
</section>
<footer>
<p>GAME OVER</p>
<p style="margin-top: 10px;">PRESS START TO PLAY AGAIN</p>
<p style="margin-top: 20px; color: var(--accent-cyan);">© 2025 DIGITAL SYSTEMS FUNDAMENTALS</p>
</footer>
</div>
<script>
// Binary to Decimal Converter
function convertBinToDec() {
const input = document.getElementById('binInput').value.replace(/\s/g, '');
const result = document.getElementById('binResult');
if (!/^[01]+$/.test(input)) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Invalid binary input</span>';
return;
}
let decimal = 0;
let breakdown = '';
for (let i = 0; i < input.length; i++) {
const bit = input[input.length - 1 - i];
if (bit === '1') {
const value = Math.pow(2, i);
decimal += value;
breakdown += value + (i < input.length - 1 && input[input.length - 2 - i] === '1' ? ' + ' : '');
}
}
result.innerHTML = `
<div style="color: #00ffff;">BINARY: ${input}</div>
<div style="color: #00ff00; margin-top: 10px;">DECIMAL: ${decimal}</div>
<div style="color: #808080; margin-top: 10px; font-size: 8px;">BREAKDOWN: ${breakdown}</div>
`;
}
// Decimal to Binary Converter
function convertDecToBin() {
const input = parseInt(document.getElementById('decInput').value);
const width = parseInt(document.getElementById('bitWidth').value);
const result = document.getElementById('decResult');
if (isNaN(input) || isNaN(width) || width < 1) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Invalid input</span>';
return;
}
if (input < 0 || input >= Math.pow(2, width)) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Number out of range for ' + width + ' bits</span>';
return;
}
let binary = input.toString(2).padStart(width, '0');
let formatted = binary.match(/.{1,4}/g).join(' ');
result.innerHTML = `
<div style="color: #00ffff;">DECIMAL: ${input}</div>
<div style="color: #00ff00; margin-top: 10px;">BINARY (${width}-bit): ${formatted}</div>
`;
}
// Hex to Decimal
function hexToDec() {
const input = document.getElementById('hexInput').value.toUpperCase().trim();
const result = document.getElementById('hexResult');
if (!/^[0-9A-F]+$/.test(input)) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Invalid hex input</span>';
return;
}
const decimal = parseInt(input, 16);
result.innerHTML = `
<div style="color: #00ffff;">HEX: ${input}</div>
<div style="color: #00ff00; margin-top: 10px;">DECIMAL: ${decimal}</div>
`;
}
// Hex to Binary
function hexToBin() {
const input = document.getElementById('hexInput').value.toUpperCase().trim();
const result = document.getElementById('hexResult');
if (!/^[0-9A-F]+$/.test(input)) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Invalid hex input</span>';
return;
}
let binary = '';
for (let i = 0; i < input.length; i++) {
binary += parseInt(input[i], 16).toString(2).padStart(4, '0') + ' ';
}
result.innerHTML = `
<div style="color: #00ffff;">HEX: ${input}</div>
<div style="color: #00ff00; margin-top: 10px;">BINARY: ${binary.trim()}</div>
`;
}
// Two's Complement Converter
function convertTwos() {
const input = parseInt(document.getElementById('twosInput').value);
const bits = parseInt(document.getElementById('twosBits').value);
const result = document.getElementById('twosResult');
if (isNaN(input) || isNaN(bits) || bits < 2) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Invalid input</span>';
return;
}
const minVal = -Math.pow(2, bits - 1);
const maxVal = Math.pow(2, bits - 1) - 1;
if (input < minVal || input > maxVal) {
result.innerHTML = `<span style="color: #ff00ff;">ERROR: Number out of range (${minVal} to ${maxVal}) for ${bits}-bit signed</span>`;
return;
}
let binary;
let steps = '';
if (input >= 0) {
binary = input.toString(2).padStart(bits, '0');
steps = `Positive number: ${input} = ${binary}`;
} else {
const positive = Math.abs(input).toString(2).padStart(bits, '0');
const inverted = positive.split('').map(b => b === '0' ? '1' : '0').join('');
const twos = (parseInt(inverted, 2) + 1).toString(2).padStart(bits, '0');
binary = twos;
steps = `
<div>Step 1: +${Math.abs(input)} = ${positive}</div>
<div>Step 2: Invert = ${inverted}</div>
<div>Step 3: Add 1 = ${binary}</div>
`;
}
result.innerHTML = `
<div style="color: #00ffff;">DECIMAL: ${input}</div>
<div style="color: #00ff00; margin-top: 10px;">${bits}-BIT SIGNED: ${binary}</div>
<div style="color: #808080; margin-top: 10px; font-size: 8px;">${steps}</div>
`;
}
// Binary Adder
function addBinary() {
const a = document.getElementById('addA').value.replace(/\s/g, '');
const b = document.getElementById('addB').value.replace(/\s/g, '');
const result = document.getElementById('addResult');
if (!/^[01]{6}$/.test(a) || !/^[01]{6}$/.test(b)) {
result.innerHTML = '<span style="color: #ff00ff;">ERROR: Enter two 6-bit binary numbers</span>';
return;
}
const decA = parseInt(a, 2);
const decB = parseInt(b, 2);
const sum = decA + decB;
const overflow = sum > 63;
const storedSum = sum & 0x3F; // Keep only 6 bits
const binarySum = storedSum.toString(2).padStart(6, '0');
result.innerHTML = `
<div style="color: #00ffff;">${a} (${decA}) + ${b} (${decB})</div>
<div style="color: #00ff00; margin-top: 10px;">RESULT: ${binarySum} (${storedSum})</div>
<div style="color: ${overflow ? '#ff00ff' : '#808080'}; margin-top: 10px;">
${overflow ? 'OVERFLOW! Actual sum: ' + sum + ' > 63' : 'NO OVERFLOW'}
</div>
`;
}
// Smooth scrolling for navigation
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
</script>
</body>
</html>