Data Representation
Characters, Images & Sound
What You'll Learn
- How characters are represented using binary codes and character sets
- The difference between ASCII and Unicode
- How images are stored as pixels with colour depth and resolution
- How sound is sampled and stored digitally
- Calculate file sizes for images and sound
Predict
Test your intuition about data representation
Worked Examples
Step-by-step file size calculations
Trace
Work through calculations step by step
Parsons Problems
Put steps in the correct order
Quiz
Test your knowledge
1. Representing Characters
Why Binary Codes for Characters?
Computers can only understand binary (1s and 0s). Every character you type - letters, numbers, symbols - must be converted to a binary code for the computer to store and process it.
What is a Character Set?
A character set is a collection of characters that a computer can recognise and use. It defines:
- Which characters are available (letters, numbers, symbols)
- The binary code assigned to each character
- How many bits are used per character
The Bits vs Characters Relationship
Number of characters = 2number of bits
| Bits per Character | Maximum Characters | Example |
|---|---|---|
| 7 bits | 27 = 128 | Original ASCII |
| 8 bits (1 byte) | 28 = 256 | Extended ASCII |
| 16 bits (2 bytes) | 216 = 65,536 | Unicode (basic) |
| 32 bits (4 bytes) | 232 = 4+ billion | Unicode (full) |
ASCII (American Standard Code for Information Interchange)
ASCII is one of the oldest and most widely used character sets. In exams, ASCII uses 8 bits per character.
ASCII Key Facts
- Uses 8 bits (1 byte) per character
- Can represent 256 different characters (28)
- Includes: uppercase letters, lowercase letters, digits 0-9, punctuation, control characters
- Only supports English and basic symbols
ASCII is Logically Ordered
Characters in ASCII follow a logical sequence:
A = 65, B = 66, C = 67, D = 68...
a = 97, b = 98, c = 99, d = 100...
0 = 48, 1 = 49, 2 = 50, 3 = 51...
Try It: ASCII Lookup
Enter a character to see its ASCII code:
Unicode
Unicode was created to solve ASCII's limitations. It can represent characters from every language in the world, plus emojis and symbols!
| Feature | ASCII | Unicode |
|---|---|---|
| Bits per character | 8 bits (1 byte) | 8-32 bits (1-4 bytes) |
| Total characters | 256 | Over 140,000 |
| Languages | English only | All world languages |
| Emojis | No | Yes |
| File size | Smaller | Larger |
| Compatibility | Older systems | Modern systems |
Trade-off: Characters vs File Size
More bits per character = more possible characters, but larger file sizes.
A text file in Unicode can be 2-4 times larger than the same text in ASCII!
Calculating Text File Size
Formula
File size (bits) = Number of characters ร Bits per character
File size (bytes) = Number of characters ร Bytes per character
Example: Calculate the file size of "Hello" in ASCII
- Count characters: "Hello" = 5 characters
- ASCII uses 8 bits (1 byte) per character
- File size = 5 ร 8 = 40 bits or 5 bytes
2. Representing Images
Images as Pixels
Digital images are made up of tiny squares called pixels (picture elements). Each pixel has a specific colour, represented by a binary code.
A simple 8ร8 pixel image. Zoom in on any photo to see pixels!
Resolution
Resolution is the number of pixels in an image, usually expressed as width ร height.
Common Resolutions
- HD: 1280 ร 720 = 921,600 pixels
- Full HD: 1920 ร 1080 = 2,073,600 pixels (about 2 megapixels)
- 4K: 3840 ร 2160 = 8,294,400 pixels (about 8 megapixels)
Effect of Resolution
| Higher Resolution | Lower Resolution |
|---|---|
| More pixels | Fewer pixels |
| More detail/sharper image | Less detail/blurry when enlarged |
| Larger file size | Smaller file size |
Colour Depth
Colour depth is the number of bits used to represent the colour of each pixel.
Colour Depth Formula
Number of colours = 2colour depth
| Colour Depth | Number of Colours | Use Case |
|---|---|---|
| 1 bit | 21 = 2 | Black and white only |
| 4 bits | 24 = 16 | Simple graphics |
| 8 bits | 28 = 256 | GIF images |
| 24 bits | 224 = 16.7 million | "True colour" photos |
Visual Comparison
1-bit (2 colours)
8-bit (256 colours)
24-bit (16.7M colours)
Calculating Image File Size
Image File Size Formula
File size (bits) = Width ร Height ร Colour depth
File size (bytes) = (Width ร Height ร Colour depth) รท 8
Example: Calculate the file size of a 1920ร1080 image with 24-bit colour
- Total pixels = 1920 ร 1080 = 2,073,600 pixels
- Bits per pixel = 24 bits
- Total bits = 2,073,600 ร 24 = 49,766,400 bits
- Convert to bytes = 49,766,400 รท 8 = 6,220,800 bytes
- Convert to MB = 6,220,800 รท 1,000,000 โ 6.2 MB
Metadata
Metadata is additional information stored with an image file. It's "data about data".
What Metadata Includes
- Image dimensions: Width and height in pixels
- Colour depth: Bits per pixel
- File format: JPEG, PNG, GIF, etc.
- Date created: When the image was taken/created
- Camera settings: For photos - aperture, shutter speed, ISO
- GPS location: Where the photo was taken
3. Representing Sound
Analogue vs Digital Sound
Sound in the real world is analogue - a continuous wave that varies smoothly. Computers need digital data - discrete binary values.
Analogue sound wave with digital sample points
Sample Rate
Sample rate is how many samples are taken per second. It's measured in Hertz (Hz).
1 Hz = 1 sample per second
1 kHz = 1,000 samples per second
| Sample Rate | Samples per Second | Use Case |
|---|---|---|
| 8,000 Hz (8 kHz) | 8,000 | Telephone quality |
| 22,050 Hz | 22,050 | AM radio quality |
| 44,100 Hz (44.1 kHz) | 44,100 | CD quality |
| 48,000 Hz (48 kHz) | 48,000 | DVD/professional audio |
Effect of Sample Rate
| Higher Sample Rate | Lower Sample Rate |
|---|---|
| More samples per second | Fewer samples per second |
| More accurate representation | Less accurate (sounds "choppy") |
| Better quality playback | Lower quality playback |
| Larger file size | Smaller file size |
Bit Depth
Bit depth (also called sample resolution) is the number of bits used to store each sample.
| Bit Depth | Possible Values | Use Case |
|---|---|---|
| 8 bits | 28 = 256 levels | Basic audio |
| 16 bits | 216 = 65,536 levels | CD quality |
| 24 bits | 224 = 16.7 million levels | Professional studio |
Effect of Bit Depth
Higher bit depth = more precise volume levels = better dynamic range = larger files
Lower bit depth = fewer volume levels = more "noise" = smaller files
Duration
Duration is simply how many seconds of audio the sound file contains.
Calculating Sound File Size
Sound File Size Formula
File size (bits) = Sample rate ร Bit depth ร Duration (seconds)
File size (bytes) = (Sample rate ร Bit depth ร Duration) รท 8
For stereo audio, multiply by 2 (two channels)
Example: Calculate the file size of a 3-minute CD-quality audio file (mono)
- Sample rate = 44,100 Hz
- Bit depth = 16 bits
- Duration = 3 minutes = 180 seconds
- File size (bits) = 44,100 ร 16 ร 180 = 127,008,000 bits
- File size (bytes) = 127,008,000 รท 8 = 15,876,000 bytes
- File size (MB) = 15,876,000 รท 1,000,000 โ 15.9 MB
For stereo, this would be 31.8 MB (ร2 for two channels)
Quick Reference Card
Characters
- ASCII: 8 bits = 256 characters
- Unicode: 8-32 bits = 140,000+ characters
- File size = characters ร bits per char
- Characters are logically ordered (A=65, B=66...)
Images
- Made of pixels (picture elements)
- Resolution = width ร height
- Colours = 2colour depth
- File size = width ร height ร colour depth
- Metadata stores dimensions, format, etc.
Sound
- Analogue sound โ digital samples
- Sample rate in Hz (44.1kHz = CD)
- Bit depth = bits per sample (16-bit = CD)
- File size = rate ร depth ร duration
- Stereo = mono ร 2
The Universal Trade-Off
For ALL data types: Higher quality = Larger file size
More bits per item means more possible values/detail, but more storage needed.