Skip to main content
← Unit 2: Data

Code Scholars Tutoring · AP Computer Science Principles

2.1 Data Representation

How it works

Bits can represent numbers, text, images, audio, colors, and other information when a system agrees on the format.

Identify whether a question is asking about binary values, text encoding, image pixels, or file size.

Common error

Do not treat representation, encryption, compression, and hashing as the same operation.

Worked example

Interpret a short binary value and an uncompressed image representation.

Data / pseudocode

Binary: 10110
Place values: 16 8 4 2 1
Image: 20 by 10 pixels, 8 bits per pixel
Bit patternAgreed encodingInterpreted data
Bit pattern → Agreed encoding → Interpreted data

10110 represents 16 + 4 + 2 = 22. The pixel payload requires 20 * 10 * 8 = 1600 bits, or 200 bytes. This calculation excludes file headers and other metadata; actual file size can differ.

Exercises

2.1.1

Convert binary 11001 to decimal and state the number of distinct values representable with five bits.

Show solution

11001 equals 16 + 8 + 1 = 25. Five bits provide 2^5 = 32 distinct bit patterns.

2.1.2

How many bytes of uncompressed pixel data are needed for a 16 by 16 image with 24 bits per pixel, excluding headers?

Show solution

16 * 16 * 24 = 6144 bits. Dividing by 8 gives 768 bytes.

Need help with this topic?

Work through questions with a tutor and get help with the steps you find difficult.

Get help with this topic