Representing text, images, and sound
Binary can represent anything if we agree on an encoding. Text, pictures, and audio all become patterns of bits.
Character encoding
Text is stored by assigning each character a number. ASCII, from the 1960s, uses 7 bits for 128 characters, covering English letters, digits, and punctuation: 'A' is 65, 'a' is 97. ASCII cannot represent most of the world's writing systems.
Unicode and UTF-8
Unicode assigns a unique code point to over 150,000 characters across the world's scripts, plus symbols and emoji. UTF-8, the dominant encoding on the web, stores ASCII characters in one byte and others in two to four bytes, keeping compatibility with ASCII. Most web pages today use UTF-8.
Images as pixels
A digital image is a grid of pixels. Each pixel's colour is often stored as red, green, and blue (RGB) values, commonly 8 bits each, giving 24 bits per pixel and about 16.7 million possible colours. A 1920 x 1080 image has about 2 million pixels, around 6 megabytes uncompressed.
Resolution and colour depth
Resolution is the number of pixels; colour depth is the bits per pixel. Higher values give better quality but larger files. Vector graphics, such as SVG files, store shapes as mathematical descriptions instead of pixels, so they scale without losing quality.
Sound
Sound is a continuous wave. To digitise it, a computer samples the wave's amplitude many times per second (the sample rate) and stores each sample with a certain number of bits (bit depth). CD audio uses 44,100 samples per second at 16 bits per sample per channel. The Nyquist theorem says the sample rate must be at least twice the highest frequency to capture it.
Compression
Compression reduces file size. Lossless compression, such as ZIP and PNG, preserves all data exactly by finding patterns and redundancy. Lossy compression, such as JPEG for images and MP3 or AAC for audio, discards details people are unlikely to notice, achieving much smaller files.
Metadata and file formats
Files contain not only the data but metadata, information about the data, such as an image's camera settings or a song's artist. File formats specify how bits are organised; a program must understand the format to interpret the file correctly. The same bits mean nothing without the right interpretation.
Worked example
One minute of uncompressed CD-quality stereo audio requires 44,100 samples per second x 16 bits x 2 channels x 60 seconds = 84,672,000 bits, about 10.6 megabytes. An MP3 at 128 kilobits per second stores the same minute in about 0.96 megabytes, roughly 11 times smaller, by discarding less audible detail.
Key takeaways
Text is encoded as numbers: ASCII uses 7 bits for 128 characters; Unicode covers over 150,000 characters, usually stored in UTF-8. Images are grids of pixels, often 24-bit RGB; vector graphics scale without loss. Sound is sampled at a sample rate and bit depth; CD audio uses 44,100 Hz at 16 bits. Lossless compression preserves data; lossy compression discards details for smaller files. Metadata and formats tell programs how to interpret bits.
Flashcard
7-bit code for 128 characters
Check your understanding
Why is a JPEG photo much smaller than the same image stored without compression?
