Number Systems

Binary, decimal, and positional notation — how computers represent numbers as voltage levels and why powers of two govern digital hardware.

Why This Matters

Every number stored in a computer — whether a temperature reading, a memory address, or a pixel color — is represented in binary (base 2). Understanding number systems is the entry point to understanding what hardware is actually doing when it processes data. Without this foundation, register contents are meaningless hex values; with it, they become interpretable quantities.

The choice of binary for computing is not arbitrary. It maps directly to physical reality: two stable voltage states, two stable magnetization directions, two optical states. Reliable discrimination between two states is far easier than between ten (decimal) or sixteen (hex) states. Binary is the natural language of electricity.

Converting between binary, decimal, and hexadecimal is a fundamental practical skill for anyone reading machine code, debugging hardware registers, or writing firmware.

Positional Number Systems

All common number systems are positional: the value of each digit depends on its position (its column) in the number. The position determines which power of the base that digit is multiplied by.

In decimal (base 10), the number 4,327 means: 4 × 10³ + 3 × 10² + 2 × 10¹ + 7 × 10⁰ = 4,000 + 300 + 20 + 7 = 4,327

The base determines the number of distinct digit symbols needed. Base 10 uses 0–9. Base 2 (binary) uses only 0 and 1. Base 16 (hexadecimal) uses 0–9 and A–F.

The rightmost digit is the units place (base^0 = 1). Moving left, each position multiplies by the base. Moving right of a decimal point (or binary point), each position divides by the base.

Binary: Base 2

Binary uses exactly two digits: 0 and 1. These correspond directly to LOW and HIGH voltage states in digital circuits, to magnetic south and north, to pit and land on an optical disc.

Binary place values (powers of 2):

PositionPowerValue
7 (MSB)2^7128
62^664
52^532
42^416
32^38
22^24
12^12
0 (LSB)2^01

“MSB” = most significant bit (highest place value). “LSB” = least significant bit (lowest place value).

An 8-bit byte can represent values from 0 (00000000) to 255 (11111111).

Binary to Decimal Conversion

Sum the place values of all positions where the bit is 1.

Example: convert 10110101 to decimal. Position 7: 1 × 128 = 128 Position 5: 1 × 32 = 32 Position 4: 1 × 16 = 16 Position 2: 1 × 4 = 4 Position 0: 1 × 1 = 1 Positions 6, 3, 1 are 0, contribute nothing. Total: 128 + 32 + 16 + 4 + 1 = 181

Decimal to Binary Conversion

Method 1: Repeated division by 2. Divide the number by 2 repeatedly, recording remainders. The remainders, read from bottom to top, form the binary representation.

Convert 181 to binary: 181 ÷ 2 = 90 remainder 1 90 ÷ 2 = 45 remainder 0 45 ÷ 2 = 22 remainder 1 22 ÷ 2 = 11 remainder 0 11 ÷ 2 = 5 remainder 1 5 ÷ 2 = 2 remainder 1 2 ÷ 2 = 1 remainder 0 1 ÷ 2 = 0 remainder 1

Reading remainders bottom to top: 10110101. Matches the original example. ✓

Method 2: Subtractive (for manual use). Find the largest power of 2 not exceeding the number, set that bit, subtract, and repeat. 181 ≥ 128: set bit 7, remaining = 53 53 < 64: bit 6 = 0 53 ≥ 32: set bit 5, remaining = 21 21 ≥ 16: set bit 4, remaining = 5 5 < 8: bit 3 = 0 5 ≥ 4: set bit 2, remaining = 1 1 < 2: bit 1 = 0 1 ≥ 1: set bit 0 Result: 10110101 ✓

Signed Binary: Two’s Complement

For negative numbers, computers use two’s complement notation. In an 8-bit two’s complement number:

  • If bit 7 (MSB) = 0: the number is non-negative (0 to 127)
  • If bit 7 (MSB) = 1: the number is negative (-128 to -1)

To negate a number in two’s complement:

  1. Invert all bits (one’s complement)
  2. Add 1

Example: represent -5 in 8-bit two’s complement. 5 = 00000101 Invert: 11111010 Add 1: 11111011

So -5 = 11111011. Verify: 11111011 in unsigned = 251. 251 - 256 = -5. ✓

Two’s complement is used because addition hardware works identically for signed and unsigned numbers — no special subtraction circuit is needed. To subtract B from A, compute A + (-B) = A + (two’s complement of B).

Important Powers of 2

Memorize these:

PowerValue
2^01
2^12
2^24
2^38
2^416
2^532
2^664
2^7128
2^8256
2^101,024 (1 Ki)
2^1665,536 (64 Ki)
2^201,048,576 (1 Mi)

These appear constantly: 256 colors (8-bit color), 1024 bytes per kilobyte, 65536 ports in TCP/IP (16-bit port field), 4 GB address space (32-bit addressing = 2^32 = 4,294,967,296 bytes).

The “kilo” in computing (1 KiB = 1,024 bytes) differs from the SI kilo (1,000). This causes endless confusion in storage sizes — a hard drive manufacturer using SI kilobytes reports larger numbers than an OS using binary kilobytes for the same physical capacity.