📘 CodingMarble Learn

Data Representation: How Computers Store Numbers, Text, Images and Sound

Data is raw facts; information is data given meaning; knowledge is information we can use. A computer stores all data as bits (0 or 1). 8 bits make a byte, and 1 kB = 1000 bytes, 1 MB = 1000 kB, 1 GB = 1000 MB, 1 TB = 1000 GB. Numbers are stored in binary, where place values double: 1, 2, 4, 8 and so on. Text uses a character set: in ASCII 'A' is 65; Unicode covers every script. A bitmap image is a grid of pixels; size = width × height × colour depth. Sound is sampled: size = sample rate × bit depth × seconds. Vector images store shapes instead of pixels. Compression makes files smaller: lossless keeps every bit, lossy throws some detail away.

🎬 Step-by-step story

  1. A computer stores everything as switches. On = 1, off = 0. One switch is a bit; 8 bits are a byte.
  2. In binary each place is worth double the one on its right. Add the places that are on: 01001101 = 77.
  3. Letters are numbers too. A character set gives each letter a code: in ASCII, A = 65.
  4. A bitmap picture is a grid of pixels. Each pixel stores a colour code; more bits per pixel means more colours.
  5. Sound is a smooth wave. The computer measures it many times a second. Each measurement is a sample.
  6. Free play: pick a number from 0 to 255 and watch its 8 bits and its letter.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why do computers use binary and not 0–9?

A switch has only two safe states, on and off. Two states are easy to make and hard to confuse, even with electrical noise.

Why is my 1 TB drive shown as about 931 GB?

The maker counts 1 TB = 1 000 000 000 000 bytes. Some computers divide by 1024 three times (GiB) and show a smaller number. No space is missing.

How do I know which place is 128?

Start at the right with 1 and keep doubling to the left: 1, 2, 4, 8, 16, 32, 64, 128.

How does the computer know 65 means 'A' and not a number?

It does not know by itself. The program decides to read those bits as text using a character set.

Why does a zoomed photo look blocky?

It has a fixed number of pixels. Zooming just makes each square pixel bigger.

Why not sample sound a million times a second for perfect quality?

File size grows with sample rate. Above about twice the highest frequency we can hear, extra samples add size but no difference we can hear.

Data, information and knowledge

Data are raw facts: numbers, words, sounds or pictures with no meaning yet. Example: 38, 39, 41.

Information is data that has been put in order and given meaning. Example: "The temperature in Delhi rose from 38 °C to 41 °C this week."

Knowledge is information we understand well enough to act on. Example: "It will be hot, so drink more water."

Good data is accurate, complete, up to date and relevant to your goal. We process data to get information: we collect it, search it, sort it, edit it and calculate with it. Before you collect data, decide your goal, then choose only the data that helps that goal.

Bits, bytes and units of information

Inside a computer, millions of tiny switches can be on (1) or off (0). One such 0-or-1 is a bit (binary digit). 4 bits are a nibble and 8 bits are a byte.

UnitSize
1 kilobyte (kB)1000 bytes
1 megabyte (MB)1000 kB
1 gigabyte (GB)1000 MB
1 terabyte (TB)1000 GB

These are the SI (decimal) prefixes. Some books and operating systems use powers of 2 instead: 1 kibibyte (KiB) = 1024 bytes, 1 MiB = 1024 KiB.

Binary numbers

In our normal (denary) system, places are worth 1, 10, 100. In binary the places are worth 1, 2, 4, 8, 16, 32, 64, 128 — each one double the last. To change binary to denary, add the place values that have a 1. To change denary to binary, take away the biggest place value that fits, write 1 there, and repeat. With n bits you can make 2n different patterns, so one byte stores 0 to 255. A logical value (true/false) needs just 1 bit. Hexadecimal (base 16) is a short way to write binary: one hex digit = 4 bits, so 1111 1111 = FF.

Representing text: ASCII and Unicode

A character set is a table that gives every character a number (its code). The computer stores the code in binary.

Encoding is a choice: the same bits can mean a number, a letter or a colour. The program decides how to read them.

Representing images: bitmap and vector

A bitmap (raster) image is a grid of pixels (picture elements). Each pixel stores one colour as a binary code.

A vector image stores a list of objects (lines, circles, rectangles, text) with their properties: position, size, line colour, fill colour, thickness. The computer draws them fresh each time.

BitmapVector
Good forphotos, rich detaillogos, icons, maps, diagrams
When enlargedbecomes blocky (pixelated)stays sharp
File sizegrows with pixelsusually small; grows with number of objects

Representing sound, and making files smaller

Sound in air is analogue: it changes smoothly. A computer is digital: it stores separate numbers. An ADC (analogue-to-digital converter) measures the wave many times a second; a DAC turns the numbers back into a wave for the speaker.

Compression

Lossless compression makes a file smaller and gives back every bit exactly (ZIP, PNG). Two ways: run-length encoding (RLE) stores runs, so WWWWWBBB becomes 5W3B; dictionary coding replaces repeated words with short codes. Lossy compression throws away detail people hardly notice (JPEG, MP3). Files become much smaller but can never be fully restored.

Errors and secrets

With a fixed number of bits a computer must round: 1/3 or 0.1 cannot be stored exactly, so tiny errors appear. If a result is too big for the bits it gets an overflow error. Data can also be hidden by encryption: a Caesar cipher shifts each letter (shift 3: A → D), which is easy to break; a Vernam cipher combines each character with a random key as long as the message, used only once, and cannot be broken without the key.

Showing data clearly: tables and graphs

People also represent data so that humans can read it. Pick the display that fits the data:

To judge a display, check: a title, labelled axes with units, a scale that starts at zero for bars, equal intervals, a key, and the source of the data. A cut or stretched axis can make a small change look huge.

Key formulas and definitions

Worked examples

1. Convert 01101001 (binary) to denary.

Place values: 128, 64, 32, 16, 8, 4, 2, 1. The 1s are at 64, 32, 8 and 1. 64 + 32 + 8 + 1 = 105.

2. Convert 200 (denary) to 8-bit binary.

128 fits: 200 − 128 = 72 → 1. 64 fits: 72 − 64 = 8 → 1. 32 no → 0. 16 no → 0. 8 fits: 8 − 8 = 0 → 1. 4, 2, 1 → 0. Answer: 11001000.

3. In ASCII, 'A' is 65. What is the code for 'H', and what is it in binary?

H is the 8th letter, 7 after A: 65 + 7 = 72. 72 = 64 + 8 → 01001000.

4. An image is 800 × 600 pixels with 24-bit colour. Find its size in MB.

Bits = 800 × 600 × 24 = 11 520 000. Bytes = 11 520 000 ÷ 8 = 1 440 000. MB = 1 440 000 ÷ 1 000 000 = 1.44 MB.

5. A 30-second mono sound clip uses 44 100 Hz and 16 bits per sample. How big is it in kB?

Bits = 44 100 × 16 × 30 = 21 168 000. Bytes = 2 646 000. kB = 2646 kB (about 2.6 MB).

6. Compress the row of pixels WWWWBBBBBBWW with run-length encoding. How many characters are saved?

Runs: 4 W, 6 B, 2 W → 4W6B2W. The original has 12 characters, the code has 6, so 6 are saved (50%). RLE is lossless: we can rebuild the row exactly.

Common mistakes

Practice quiz

1. How many bits are in one byte?
2. What is 1010 in denary?
3. Which increases the size of a bitmap image?
4. Which type of image stays sharp when enlarged?
5. MP3 music is an example of:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is data representation in computers?

It is how numbers, text, images and sound are turned into bits (0s and 1s) so a computer can store and process them.

What is the formula for image file size?

Size in bits = width in pixels × height in pixels × colour depth. Divide by 8 to get bytes.

What is the difference between lossy and lossless compression?

Lossless makes the file smaller and lets you get back every bit. Lossy removes some detail for a much smaller file, and that detail cannot be restored.

Where this is taught

NetherlandsHAVO 4 (bovenbouw, 2e fase)Information
NetherlandsVWO 4 (bovenbouw, 2e fase)Statistics and probability (part 1)
NetherlandsVWO 4 (bovenbouw, 2e fase)Statistics and probability (part 1)
NetherlandsVWO 5Information
PolandLiceum ogólnokształcące, klasa IUnderstanding, analysing and solving problems
England (GCSE, A level)Year 103.3 Fundamentals of data representation
England (GCSE, A level)Year 113.4 Geographical skills
England (GCSE, A level)Year 124.5 Fundamentals of data representation
England (GCSE, A level)Year 134.5 Data representation (A-level)
England (GCSE, A level)Year 133.13 Electronics
USA (Common Core, NGSS, AP)Grade 8Data and Analysis
USA (Common Core, NGSS, AP)Grade 8MS-PS4 Waves
USA (Common Core, NGSS, AP)Grade 9Data and Analysis
USA (Common Core, NGSS, AP)Grade 10Big Idea 2: Data
USA (Common Core, NGSS, AP)Grade 10Big Idea 3: Algorithms and Programming
USA (Common Core, NGSS, AP)Grade 12Waves and electromagnetic radiation
Japan高校(専門学科)1〜3年Representing and Managing Information
FrancePremièreSound and music
FranceTerminaleLab sciences: Waves
Russia7 классTheoretical foundations
Russia7 классTheoretical foundations
Russia10 классTheoretical foundations
Russia10 классTheoretical foundations
China高一Comp.1 Ch.1 Data and big data

Learn next

Related lessons

All Computer Science lessons