computer hardware25 min

Bare Metal

What a computer actually is at the physical level — circuits, transistors, and binary

0/9Not Started

Why This Matters

Without hardware, software is just an idea. Every program you write — every variable, every loop, every function call — eventually becomes electrical signals flowing through physical circuits. Understanding the physical layer helps you reason about performance limits, power consumption, and why computers work the way they do.

When you hear that a processor has "billions of transistors," you should know what that means. When someone says a file is "4 kilobytes," you should understand why that number matters at the hardware level. This lesson takes you to the very bottom of the stack: the raw metal and electricity that make computation possible.

Define Terms

Visual Model

Transistortiny switch
Logic GateAND / OR / NOT
Adder Circuitbinary addition
ALUarithmetic unit
CPUprocessor

The full process at a glance. Click Start tour to walk through each step.

From transistors to a CPU: tiny switches combine into logic gates, then arithmetic circuits, then a complete processor.

Code Example

Code
// Binary representation in JavaScript
const decimal = 42;
const binaryString = decimal.toString(2);
console.log(binaryString);  // "101010"

// Parsing binary back to decimal
const backToDecimal = parseInt("101010", 2);
console.log(backToDecimal);  // 42

// Bitwise operations — these map directly to logic gates
const a = 0b1100;  // 12 in binary
const b = 0b1010;  // 10 in binary

console.log((a & b).toString(2));   // AND: "1000" (8)
console.log((a | b).toString(2));   // OR:  "1110" (14)
console.log((~a >>> 0).toString(2)); // NOT: flips all 32 bits
console.log((a ^ b).toString(2));   // XOR: "0110" (6)

// Bit shifting
console.log((1 << 3));  // Left shift: 1 becomes 8 (1000 in binary)
console.log((8 >> 2));  // Right shift: 8 becomes 2 (10 in binary)

// How computers see characters
console.log("A".charCodeAt(0));          // 65
console.log((65).toString(2));           // "1000001"
console.log(String.fromCharCode(65));    // "A"

Interactive Experiment

Try these exercises:

  • Convert the number 255 to binary. Why does it produce all 1s? (Hint: think about how many values 8 bits can represent.)
  • What is 0b1111 & 0b1010? Work it out by hand before running the code.
  • Use left shift (<<) to calculate powers of 2. What is 1 << 10? Why is this number familiar to programmers?
  • Convert your first initial to its ASCII code, then to binary. How many bits does it take?

Quick Quiz

Coding Challenge

Decimal to Binary Converter

Write a function called `decimalToBinary` that takes a non-negative integer and returns its binary representation as a string. Do not use built-in conversion methods like toString(2) or bin(). Instead, build the binary string yourself using repeated division by 2.

Loading editor...

Real-World Usage

The physical layer is not just theory — it directly shapes modern technology:

  • Transistor counts: Apple's M2 chip has over 20 billion transistors. Intel's latest server CPUs have over 100 billion. More transistors means more computational capability packed into a single chip.
  • Moore's Law: Gordon Moore observed in 1965 that the number of transistors on a chip doubles roughly every two years. This trend held for decades and drove the exponential growth of computing power.
  • ARM vs x86: ARM processors (used in phones and Apple Silicon) use fewer transistors per instruction, consuming less power. x86 processors (Intel, AMD) prioritize raw performance with more complex instruction sets. The tradeoff is power efficiency versus computational throughput.
  • Quantum computing: Quantum computers replace transistors with qubits that can exist in superposition — simultaneously 0 and 1. This is a fundamentally different approach to the binary foundation covered in this lesson.
  • Bitwise operations in practice: Graphics engines, network protocols, compression algorithms, and cryptography all rely heavily on bit-level manipulation for performance.

Connections