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 (Base 10) | Binary (4-bit) | Hexadecimal (Base 16) | Where You See It |
|---|---|---|---|
| 0 | 0000 | 0 | Black pixel channel / Logic LOW |
| 5 | 0101 | 5 | 4 + 1 (alternating bit mask) |
| 10 | 1010 | A | In base 16, letter A = 10 |
| 12 | 1100 | C | 8 + 4 (letter C = 12 in Hex) |
| 15 | 1111 | F | Max 4-bit value (one nibble); F = 15 |
| 255 | 11111111 | FF | Max 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!
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:
- 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.
- DECODE: The Control Unit decodes the opcode (e.g., LOAD, ADD, STORE, JZ) and places any operand address into MAR.
- EXECUTE: The Arithmetic Logic Unit (ALU) runs the math or logic operation using the Accumulator (ACC) and updates ZERO_FLAG for branching.
- 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:
// 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;