2. How Computers Represent Data

How Computers Represent Data

A computer has no concept of letters, colours, or music. Underneath everything it stores and moves numbers, and those numbers are written in a two-symbol system called binary. Understanding this layer removes a lot of the mystery from programming.

Bits and Bytes

The smallest unit of information is a bit — a single switch that is either 0 (off) or 1 (on). A single bit is not very useful, so bits are grouped. Eight bits together form one byte. One byte can represent 256 different values (from 0 to 255), which is enough to store a single character of English text.

Analogy: a bit is like one light switch, which only tells you "on or off". A byte is a row of eight switches — by choosing a pattern across all eight, you can signal 256 distinct messages.

Why Binary?

Computers use binary because electronic circuits are naturally good at two clear states: high voltage or low voltage, current flowing or not. Two states are reliable and cheap to build, so the whole machine is designed around counting in twos instead of the tens we humans use.

Binary Place Values

In our familiar decimal system each column is worth ten times the one to its right (1, 10, 100…). In binary each column is worth two times the one to its right. Here are the place values of one byte:

Bit position8th7th6th5th4th3rd2nd1st
Place value1286432168421
Example bits01001101

To read the example, add the place values wherever a bit is 1: 64 + 8 + 4 + 1 = 77. So the binary number 01001101 equals 77 in decimal.

0128 164 032 016 18 14 02 11 1 byte = 8 bits → 01001101 = 77

Converting Decimal to Binary

To turn a decimal number into binary, repeatedly ask "does the largest remaining place value fit?" For 77: 128 is too big (0), 64 fits (1, leaving 13), 32 no (0), 16 no (0), 8 fits (1, leaving 5), 4 fits (1, leaving 1), 2 no (0), 1 fits (1). That reproduces 01001101.

Hexadecimal: A Shorthand

Long strings of 0s and 1s are hard for humans to read, so programmers often use hexadecimal (base 16). Hex uses sixteen symbols: 0–9 then A–F (where A=10 … F=15). One hex digit neatly represents exactly four bits, so two hex digits describe one byte.

DecimalBinaryHex
000000
501015
101010A
151111F
770100 11014D
2551111 1111FF

Text, Images, and Sound Are Numbers Too

  • Text: Each character is assigned a number. The old ASCII standard maps A to 65, a to 97, and so on. Modern Unicode extends this to cover every language's characters plus emoji.
  • Images: A picture is a grid of tiny dots called pixels. Each pixel stores numbers for its red, green, and blue brightness — typically one byte each, giving millions of possible colours.
  • Sound: A microphone measures air pressure thousands of times per second; each measurement is saved as a number. Playing them back in order recreates the sound.

The big takeaway: everything inside a computer — this sentence, your photos, your music — is ultimately just numbers written in binary. When you program, you are arranging and transforming those numbers in meaningful ways.