Source: Foundations of Computer Science, Ch. 4 (Sections 4.0 -- 4.7)
Tags: data formats, ASCII, EBCDIC, Unicode, UTF-8, UTF-16, bitmap image, object image, vector image, pixel, GIF, JPEG, PNG, PostScript, video codec, MPEG, audio formats, MP3, WAV, data compression, lossless, lossy, metadata, collating sequence, IFT 510, Purdue
Difficulty: Intermediate
Prerequisites: Number Systems study notes (Ch. 3). Familiarity with binary and hexadecimal.
Computers store everything as binary numbers, but "everything" includes text, images, sound, and video. This chapter covers how each of those data types gets translated into binary, what standards exist for that translation, and the trade-offs involved. You need this material to understand why a JPEG looks different from a PNG, why Unicode exists, why video files are so large, and how data compression works. It also connects to how programming languages decide what a binary number "means" (is it a character, an integer, or a pixel colour?).
Text is stored using standardised character codes (Unicode, ASCII, EBCDIC), each mapping a character to a binary number. Images are either bitmaps (grids of pixel values) or object/vector images (mathematical descriptions of shapes). Sound is digitised by sampling an analog waveform at regular intervals. Video is a stream of bitmap frames, heavily compressed. Data compression is either lossless (perfectly reversible) or lossy (some information discarded for much smaller file sizes).
ASCII (American Standard Code for Information Interchange)
A 7-bit character code (128 characters) mapping English letters, digits, punctuation, and control characters to binary values. Extended to 8 bits as Latin-1 (256 characters). In simple terms, the original way computers represented text. "A" = 41 hex, "a" = 61 hex.
EBCDIC (Extended Binary Coded Decimal Interchange Code)
An 8-bit character code developed by IBM, used mainly on IBM mainframes. The collating sequence differs from ASCII (lowercase letters precede uppercase in EBCDIC; the reverse is true in ASCII). In simple terms, an older, IBM-specific alternative to ASCII that you will encounter in legacy systems.
Unicode
A modern character encoding standard supporting roughly a million characters across all the world's writing systems, emojis, and symbols. Implemented as UTF-8 (variable-width, 1 to 4 bytes), UTF-16 (2 or 4 bytes, used by Windows and Java), and UTF-32 (fixed 4 bytes). In simple terms, the universal character set that replaced ASCII for modern systems.
Collating sequence
The ordering of characters as determined by their numeric code values. Determines how text is sorted. ASCII and EBCDIC have different collating sequences, which means the same sorting program can produce different results depending on the character code in use.
Control characters
Non-printing characters in a character code that perform actions rather than display symbols. Examples: carriage return (CR), line feed (LF), tab (HT), backspace (BS), escape (ESC).
Alphanumeric data
Data consisting of letters, digits, punctuation, and symbols. Entered via keyboard and stored as character codes. Numeric characters must be explicitly converted to numerical form before arithmetic can be performed on them.
Metadata
Data that describes other data. For an image, metadata includes dimensions, colour depth, format type, and compression method. For audio, it includes sampling rate, bit depth, and number of channels.
Pixel (picture element)
The smallest addressable point in a bitmap image. Each pixel stores one or more values describing its colour and intensity.
Bitmap (raster) image
An image stored as a grid of pixel values. Photographs, screenshots, and scanned images are bitmaps. Formats include JPEG, PNG, GIF, BMP, and TIFF. In simple terms, the image is a massive table of colour values, one per tiny square.
Object (vector) image
An image stored as mathematical descriptions of shapes (lines, curves, circles). Can be scaled, rotated, and resized without quality loss. Formats include SVG, PostScript, and various CAD formats. In simple terms, the image is a set of instructions ("draw a circle here, a line there") rather than a grid of dots.
Resolution
The level of detail in a bitmap image, typically measured in pixels per inch (PPI). Higher resolution means more pixels and more storage.
Palette
A lookup table mapping compact colour codes to actual colour values. Reduces storage when the number of distinct colours is small (e.g. GIF images use a 256-colour palette).
GIF (Graphics Interchange Format)
A bitmap format limited to 256 colours per image, using LZW lossless compression. Supports animation (animated GIFs) and multiple images per file.
PNG (Portable Network Graphics)
A lossless bitmap format supporting up to 48 bits of colour per pixel, plus transparency. Generally better compression than GIF for single images.
JPEG (Joint Photographic Experts Group)
A bitmap format using lossy compression. Excellent for photographs and complex images with continuous colour variation. Not ideal for line drawings or text (compression introduces artefacts on sharp edges).
PostScript
A page description language and programming language for storing, transmitting, and printing object images. Stored as plain text. Includes scalable font support and a full library of drawing functions.
Glyph
The visual, object-image-based representation of a character in a specific font. Different from the character code: the code identifies which character, the glyph defines what it looks like.
Rendering
The process of converting character data into glyphs for display, then converting those glyphs into bitmap graphics for the screen or printer.
Codec (coder/decoder)
An algorithm that compresses video or audio for storage and transmission, and decompresses it for playback. Common video codecs: MPEG-2, MPEG-4, H.264. Common audio codecs: MP3, AAC.
Streaming video/audio
Media transmitted over a network and played in real time as it arrives, rather than downloaded completely before playback. Requires heavy compression.
A-to-D converter (analog-to-digital)
Hardware that samples an analog signal (such as sound) at regular intervals and converts each sample to a binary number proportional to the signal's amplitude.
Sampling rate
How many times per second an analog signal is sampled. Audio is typically sampled at 44,100 Hz (CD quality) or higher.
Lossless compression
Compression that is perfectly reversible; the original data can be restored exactly. Used for text, program files, and data files. Examples: LZW (GIF), ZIP, PNG compression.
Lossy compression
Compression that discards some data to achieve much higher compression ratios. The lost data cannot be recovered. Used for images (JPEG), audio (MP3, AAC), and video (MPEG). Acceptable because human perception has limits.
Proprietary format
A data format defined by and specific to a particular software vendor. Microsoft Word's .docx is an example.
Page description language
A language that describes the layout and content of a printed or displayed page, combining text, images, and other objects. Examples: HTML, PostScript, PDF.
Characters enter the computer as binary codes, typically from a keyboard. The choice of code is arbitrary from the computer's perspective (it only sees numbers), but consistency between input and output devices is essential.
Three major character codes:
ASCII: 7-bit original (128 characters), extended to 8-bit Latin-1 (256 characters). Uppercase A = 41 hex, lowercase a = 61 hex. Digits "0" through "9" = 30 hex through 39 hex. Numbers sort before uppercase letters, which sort before lowercase.
EBCDIC: 8-bit, IBM-developed. Lowercase letters sort before uppercase (opposite of ASCII). Numbers sort last. Uppercase G = C7 hex.
Unicode: Up to 32 bits. ASCII Latin-1 occupies codes 0000 through 00FF, so conversion from ASCII is trivial (just pad with leading zeros). UTF-16 is the standard form for Windows and Java, representing the 65,536 most common characters in 2 bytes each. Supports all modern languages, historical scripts, mathematical symbols, and emojis.
Collating sequence matters: A sort program designed for ASCII may produce incorrect results on EBCDIC data, and vice versa. In ASCII, "9" < "A" < "a". In EBCDIC, "a" < "A" < "9".
Printing vs. control characters: The first 32 codes in ASCII (00 through 1F hex) are control characters. Tab = 09 hex, Line Feed = 0A hex, Carriage Return = 0D hex. Control characters are generated by holding the Control key and pressing a letter (Ctrl-A = SOH = 01 hex).
Storage capacity example: In UTF-16 (2 bytes per character), a 1 GB flash drive holds roughly 500 million characters, or about 160,000 pages of text.
A rectangular grid of pixels, stored row by row from top-left to bottom-right. Each pixel is a set of binary values representing colour and intensity.
Black-and-white image: 1 bit per pixel (0 = black, 1 = white)
16 grey levels: 4 bits per pixel
True colour: 3 bytes per pixel (one byte each for red, green, blue), giving 16.7 million colours
High-definition image (1920 x 1080, true colour): approximately 6 MB uncompressed
Key formats:
GIF: Up to 256 colours, lossless LZW compression, supports animation and multiple images per file. Good for simple graphics and icons.
PNG: Up to 48 bits per pixel, lossless compression, supports transparency. Better than GIF for most purposes except animation.
JPEG: Lossy compression, excellent for photographs, poor for sharp edges and line art. Compression ratio adjustable (higher compression = lower quality).
BMP/TIFF: Uncompressed or lightly compressed bitmap formats.
Stored as mathematical descriptions of geometric shapes (lines, curves, circles, arcs). Each object is defined by a small number of parameters (e.g. a circle needs x, y, and radius).
Can be scaled, rotated, and resized without quality loss
Require far less storage than bitmap equivalents
Must be converted to bitmap for display or printing (a process called rasterisation)
Cannot represent photographs or continuous-tone images
Examples: SVG, PostScript, CAD formats, the charts in Excel
Shrek and Toy Story are created entirely from object images
PostScript is both a page description language and a programming language. It stores images as text-based programs that an interpreter executes to produce output. It includes scalable fonts, drawing functions (arcs, lines, Bezier curves), fill and shading operations, and full programming constructs (loops, conditionals, procedures).
Video is a sequence of bitmap frames displayed rapidly (typically 30 frames per second). Uncompressed, a single minute of HD video (1920 x 1080, true colour, 30 fps) would consume about 10.4 GB.
Compression is essential. Video codecs exploit the fact that most of the image does not change much from frame to frame.
MPEG-2, MPEG-4, H.264: Major codec standards. H.264 can achieve compression ratios near 1000:1 on HD video.
Containers: Wrappers that combine video and audio streams and handle encoding/decoding. Examples: HTML5 video, M4V (Apple), WebM (Google), OGG.
Sound is an analog waveform converted to digital by sampling at regular intervals using an A-to-D converter.
Sampling rate: Typically 44,100 Hz for CD-quality audio (44,100 samples per second)
Bit depth: Number of bits per sample (8-bit or 16-bit are common)
Channels: Mono (1 channel) or stereo (2 channels)
Key formats:
.WAV: Microsoft format. Simple, uncompressed. Header contains sampling rate, bit depth, channel count. Good for short sound clips.
MP3: Lossy psychoacoustic compression. Typically 1/10 the size of an equivalent WAV file. Eliminates sounds the listener cannot hear (e.g. quiet sounds masked by louder ones). Bit rates of 128 or 192 kbps are common.
AAC: Similar to MP3, derived from MPEG-4. Used by Apple and many streaming services.
MIDI: Not a sound recording. A set of instructions for synthesising music (which notes, how loud, which instrument). Very small file sizes.
Lossless compression eliminates redundancy without losing any data.
Run-length encoding: replace repeated values with a count (e.g. "00000" becomes "0,5")
Pattern substitution: replace repeated sequences with a short code
Examples: ZIP files, GIF, PNG
Lossy compression discards data deemed imperceptible to humans.
JPEG removes subtle colour changes in textured areas
MP3 removes sounds masked by louder sounds (psychoacoustic model)
Video codecs transmit only the changes between frames
Compression ratios of 10:1 or more are common
The lost data cannot be recovered
Lossy compression is never acceptable for text files, program files, or numerical data. It is commonly used for multimedia.
Inside the computer, all data is binary numbers. The meaning of those numbers depends on the processor's instruction set and the programming language's data types.
Five common simple data types:
Boolean: true or false (stored as a small integer)
char: a single character code
enumerated: user-defined set of named values (stored as integers internally)
integer: whole numbers, positive or negative
real/float: numbers with fractional parts or very large/small magnitudes
Numeric characters ("1", "2", "3") enter the computer as character codes and must be explicitly converted to integer or float form before arithmetic. The ASCII code for "0" is 48 (30 hex), so converting a digit character to its numeric value requires subtracting 48 from its ASCII code.
Storage for an uncompressed bitmap:
Storage (bytes) = width x height x (bits per pixel / 8)
Uncompressed video data rate:
Data rate = width x height x (bytes per pixel) x (frames per second)
HD video example:
1920 x 1080 x 3 x 30 = 186,624,000 bytes/sec ≈ 178 MB/sec
When you choose between JPEG and PNG for a web image, you are choosing between lossy and lossless compression, trading file size against edge sharpness. When your Python script gives you 0.30000000000000004 instead of 0.3, the cause is the binary fraction representation from Chapter 3. When you set a file permission with chmod 755, the "7" and "5" are octal digits representing binary permission flags. Unicode is why you can put emoji in a tweet and have it display correctly on any modern device worldwide.
Students often think numbers typed on a keyboard enter the computer as numbers. They do not. They enter as character codes ("1" = ASCII 31 hex) and must be converted to numerical form by software.
Assuming JPEG is always better than PNG (or vice versa). JPEG is better for photographs; PNG is better for line art, text, and images needing transparency.
Thinking lossy compression permanently damages a file every time it is opened. The damage happens at compression time. Once compressed, opening and viewing the file does not degrade it further. However, re-compressing an already-lossy file does add further degradation.
Confusing a codec with a container. The codec (H.264, MPEG-4) defines how the video data is compressed. The container (MP4, WebM, OGG) is the file wrapper that holds the compressed data plus metadata.
⚠️ Know the three major character codes (Unicode, ASCII, EBCDIC) and their key differences, particularly collating sequence order.
⚠️ ASCII "A" = 41 hex, ASCII "a" = 61 hex, ASCII "0" = 30 hex. These values come up in conversion questions.
⚠️ Understand the difference between bitmap and object images, and when each is appropriate.
⚠️ Know the distinction between lossless and lossy compression and be able to name examples of each.
⚠️ Understand what metadata is and why it is necessary for bitmap images and audio files.
⚠️ The storage calculation for uncompressed bitmaps (width x height x bytes per pixel) is a common exam problem.
⚠️ Know that Unicode's first 256 characters are identical to ASCII Latin-1, making conversion trivial.
1. True or false: In ASCII, uppercase letters have lower code values than lowercase letters. True. "A" = 41 hex, "a" = 61 hex.
2. Fill in the blank: A 1920 x 1080 true-colour image with 3 bytes per pixel requires approximately ______ MB uncompressed. 6 MB (1920 x 1080 x 3 = 6,220,800 bytes ≈ 6 MB).
3. True or false: GIF supports more than 256 colours per image. False. GIF is limited to 256 colours per image.
4. Fill in the blank: JPEG uses ______ compression, while PNG uses ______ compression. Lossy; lossless.
5. True or false: EBCDIC and ASCII assign the same binary code to the letter "G". False. ASCII "G" = 47 hex. EBCDIC "G" = C7 hex.
Q: What is the ASCII code (in hex) for the character "7"?
A: 37 hex. (The digit characters "0" through "9" occupy codes 30 through 39 in hex.)
Q: How much storage does one minute of uncompressed HD video require (1920 x 1080, 3 bytes per pixel, 30 fps)?
A: 1920 x 1080 x 3 x 30 x 60 ≈ 11.2 billion bytes ≈ 10.4 GB.
Q: Why is hexadecimal commonly used to display character codes?
A: Each byte is exactly two hex digits, making binary data compact and easy to read. Converting between hex and binary is a simple four-bit grouping.
Q: Name two advantages of object (vector) images over bitmap images.
A: They can be scaled and rotated without quality loss, and they require far less storage for geometric shapes.
Q: What is the difference between a codec and a container in video formats?
A: A codec (e.g. H.264) is the algorithm that compresses and decompresses the video data. A container (e.g. MP4, WebM) is the file format that wraps the compressed video and audio streams together with metadata.
Q: Why must the integer and fractional parts of a mixed number be converted separately when changing bases?
A: Because the radix point is the fixed reference. Shifting it to eliminate the fraction changes the value by a factor of the original base, not the target base, so the shift cannot be undone after conversion.
Character codes connect back to the binary and hex number systems from Chapter 3 (every ASCII code is a hex value you can convert to binary). The bitmap storage calculations use the range formula (bits per pixel determines the number of possible colour values: 2^n). Data compression connects to the trade-offs in computer architecture (processing power vs. storage/bandwidth). The internal data types (integer, float, char, Boolean) are explored further in Chapter 5 (numeric representation) and in programming language courses. Video and audio codecs are a major application area for the algorithms and hardware covered later in the course.
Related Terms / Search Tags: character encoding, ASCII table, EBCDIC table, Unicode UTF-8 UTF-16, collating sequence, control characters, bitmap raster image, vector object image, pixel, resolution, GIF PNG JPEG BMP TIFF, PostScript PDF, video codec MPEG H.264, audio format MP3 WAV AAC MIDI, A-to-D converter, sampling rate, lossless compression, lossy compression, metadata, data types, IFT 510 Quiz 3, Purdue computer science