🚀
ArkyEdu BLOG TIC
RO Open App
Algorithms & Architecture Grades 5–8 · Foundations 13 min read

From 0 and 1 to a Working CPU: Binary, ASCII, RGB Colors, Logic Gates & Von Neumann Architecture

One of the best questions in computer science is: „How can a piece of silicon that only knows 0 and 1 run 3D games, play music, and compile C++ code?” The answer connects every grade level—from computer hardware and RGB pixels to bitwise logic and CPU registers.

💬 WhatsApp ← ICT Blog & Guides
Quick Answer (TL;DR)

Computers only understand two voltage states—0 (OFF) and 1 (ON)—called bits. Eight bits make 1 Byte (0–255), enough for an ASCII letter or one RGB color channel. Millions of transistor logic gates (AND, OR, NOT, XOR) add numbers inside the ALU while the CPU runs the endless Fetch → Decode → Execute loop.

1. Binary (Base 2) & Hexadecimal (Base 16): The Powers-of-Two Method

Humans count in base 10 because we have 10 fingers (place values 1, 10, 100...). A wire only carries two distinct voltage levels (0 and 1), so each place from right to left represents a power of 2: 1, 2, 4, 8, 16, 32, 64, 128.

To convert any number from 0 to 255 into 8-bit binary without mistakes: scan from 128 down to 1, write „1” whenever the power fits inside the remainder and subtract it, otherwise write „0”.

Decimal – 4-Bit Binary – Hexadecimal conversion chart (used in memory & web colors)
Decimal (Base 10)Binary (4-bit)Hexadecimal (Base 16)Where You See It
000000Black pixel channel / Logic LOW
5010154 + 1 (alternating bit mask)
101010AIn base 16, letter A = 10
121100C8 + 4 (letter C = 12 in Hex)
151111FMax 4-bit value (one nibble); F = 15
25511111111FFMax 1-byte RGB channel (#FFFFFF = White)

2. How Bits Turn Into Text (ASCII / UTF-8) & Screen Colors (24-Bit RGB)

Once we can store numbers 0–255 in 1 Byte, universal standards assign clear meanings to those numbers:

In ASCII, uppercase "A" is code 65 (01000001 in binary), "B" is 66, and lowercase "a" is 97 (always +32, which flips bit 5!). Digit character "0" is ASCII 48, not the number 0. Modern apps use UTF-8/Unicode for Romanian diacritics and emojis.

For graphics, every monitor pixel mixes three sub-lights: Red (R), Green (G), and Blue (B), each using 1 Byte (0–255). Together, 3 Bytes = 24 bits per pixel produce 256 × 256 × 256 = 16,777,216 distinct colors!

Try the Live 8-Bit Switchboard & 24-Bit RGB Mixer

Inside the ArkyEdu Visual Algorithms & CPU Lab, toggle the 8 LED switches (128..1) manually to watch Decimal, Hexadecimal, ASCII, and live RGB color update instantaneously!

3. Logic Gates (AND, OR, NOT, XOR) & The Binary Half-Adder

Inside modern CPUs, billions of microscopic transistors are wired into fundamental logic gates that transform input bits A and B:

  • AND Gate: Outputs 1 only when BOTH inputs are 1 (otherwise 0). Used for bit masking and strict checks.
  • OR Gate: Outputs 1 if AT LEAST ONE input is 1.
  • NOT Gate (Inverter): Flips the bit (0 becomes 1; 1 becomes 0).
  • XOR Gate (Exclusive OR): Outputs 1 only when inputs DIFFER (one 0 and one 1). Essential for binary addition and encryption!
  • Half-Adder Circuit: Wiring just one XOR gate (Sum bit S = A XOR B) and one AND gate (Carry bit C = A AND B) lets silicon add two bits together!

4. Von Neumann Architecture & The Fetch–Decode–Execute Cycle

In 1945, John von Neumann described the stored-program computer: both program instructions and data live in the same RAM, and the CPU runs an endless three-step loop:

  1. FETCH: The Program Counter (PC) holds the RAM address of the next instruction. The CPU fetches it into the Instruction Register (IR) and increments PC.
  2. DECODE: The Control Unit decodes the opcode (e.g., LOAD, ADD, STORE, JZ) and places any operand address into MAR.
  3. EXECUTE: The Arithmetic Logic Unit (ALU) runs the math or logic operation using the Accumulator (ACC) and updates ZERO_FLAG for branching.
  4. REPEAT: A 3.5 GHz processor repeats clock ticks 3.5 billion times every second!

5. Fast Bitwise Operators in C++ (&, |, ^, <<, >>)

In competitive C++ and Arduino microcontroller code, bitwise operators manipulate individual bits directly inside CPU registers in a single clock cycle:

Essential C++ Bitwise Tricks for Students
// 1. Even / Odd check via lowest bit (faster than % 2)
if (n & 1) cout << "Odd"; else cout << "Even";

// 2. Instant multiply or divide by powers of 2 (bit-shifting)
int doubled = n << 1;     // same as n * 2
int timesFour = n << 2;   // same as n * 4
int halved = n >> 1;      // same as n / 2 (for n >= 0)

// 3. Check whether bit k (0-indexed) is ON:
bool isBitSet = (n >> k) & 1;
Shifting left by k bits (<< k) multiplies by 2^k, while shifting right (>> k) divides by 2^k.

✅ Binary, Logic Gates & CPU Architecture Checklist

  • I know powers of two from 2^0 = 1 up to 2^10 = 1,024 by heart.
  • I understand that 1 Byte = 8 bits = 0..255 (one ASCII char or one RGB color channel).
  • I can write truth tables for AND, OR, NOT, and XOR and explain how XOR + AND build a Half-Adder.
  • I can trace Fetch → Decode → Execute using PC, IR, MAR, and ACC registers.

❓ Frequently Asked Questions

What is the difference between a bit (b) and a Byte (B)?
A single bit (lowercase b) holds 0 or 1. One Byte (uppercase B) groups 8 bits together, allowing 2^8 = 256 unique combinations (0 to 255).
Why is 1 Kilobyte 1,024 Bytes instead of 1,000?
Computers address memory in powers of 2, and 2^10 = 1,024 is the binary power closest to 1,000.
What makes the XOR gate special in computing?
XOR outputs 1 only when its two inputs differ (0 and 1). It computes single-bit binary addition without carry, forming the heart of every CPU adder circuit.
What are PC, IR, and ACC inside a Von Neumann CPU?
PC (Program Counter) points to the next instruction address, IR (Instruction Register) holds the current instruction being decoded, and ACC (Accumulator) stores ALU math results.
Where can students interact with a binary switchboard and live Von Neumann CPU?
Inside the ArkyEdu Visual Algorithms, Binary & CPU Lab (/laborator-algoritmi/), featuring an 8-bit LED switchboard, logic gate bench, and editable 16-cell RAM CPU simulator.

More Study Guides

← Back to Blog Index