How do computers represent all data using only bits, and what are the consequences of fixed-size representation?
Topic 2.1 Binary Numbers: computers represent all data with bits (binary digits); numbers, text, images and sound are encoded in binary, and fixed bit-widths cause overflow and rounding.
A focused answer to AP CSP Topic 2.1, covering bits and bytes, binary-to-decimal conversion, why all data is represented in binary, analog versus digital, fixed bit-width consequences (overflow and rounding errors), and abstraction in data representation.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topic 2.1) wants you to understand that all data in a computer is represented with bits. A bit is a binary digit, 0 or 1; everything (numbers, text, images, sound) is ultimately a pattern of bits. You need to convert between binary and decimal, understand the difference between analog and digital data, and explain the consequences of using a fixed number of bits: overflow (a value too large for its bits) and rounding (real numbers approximated). This is the foundation of data representation in CSP.
Bits and bytes
Computers use binary because their hardware has two stable states (on/off, high/low voltage), which map naturally to 1 and 0.
Converting binary to decimal
Each position in a binary number is a power of 2, increasing from right to left: the places are ... 16, 8, 4, 2, 1. A binary number's decimal value is the sum of the place values where a 1 appears.
For 1011: places 8 4 2 1, digits 1 0 1 1, so 8 + 0 + 2 + 1 = 11.
For 11010: places 16 8 4 2 1, digits 1 1 0 1 0, so 16 + 8 + 0 + 2 + 0 = 26.
All data is binary
Analog versus digital, and the consequences of fixed bits
Analog data is continuous: it can take any value in a range (a real sound wave, a smooth dial). Digital data is discrete: it uses a finite set of bit patterns. Converting analog to digital samples and approximates the original, so some information is lost.
Because each value uses a fixed number of bits, two limits arise:
- Overflow error. When a value exceeds the largest number the available bits can store. An 8-bit unsigned counter maxes out at 255; going beyond overflows.
- Round-off (rounding) error. Real numbers (like
1/3) often cannot be represented exactly in a fixed number of bits, so they are rounded, introducing small errors that can accumulate.
Try this
Q1. Convert the binary number 1100 to decimal. [1 point]
- Cue. Places
8 4 2 1, digits1 1 0 0, so8 + 4 = 12.
Q2. Explain why a real number such as one-third might not be stored exactly in a computer. [2 points]
- Cue. A fixed number of bits can only represent finitely many values; one-third has no exact finite binary representation, so it is rounded, producing a round-off error.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2022 (style)1 marksMultiple choice. What is the decimal value of the binary number 1011?
(A) 7
(B) 11
(C) 13
(D) 1011
Show worked answer →
The answer is (B).
In binary, each digit is a power of 2, increasing right to left: the places are 8, 4, 2, 1. So 1011 is (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1) = 8 + 0 + 2 + 1 = 11. (A) miscounts a place; (C) would be 1101; (D) reads the digits as decimal, which is wrong.
Markers reward correct use of place values (powers of 2) when converting binary to decimal.
AP 2021 (style)2 marksFree response (short). A program stores a counter in a variable that can hold values from 0 to 255. Explain what happens if the program tries to increase the counter beyond 255, and name the type of error this represents.
Show worked answer →
A 2-point question on fixed bit-width and overflow.
Point 1: A value from 0 to 255 fits in 8 bits (one byte), because 8 bits represent 2 to the power of 8, that is 256 distinct values (0 to 255). Trying to store a value larger than the maximum exceeds the range the variable can represent.
Point 2: This is an overflow error: when a value exceeds the available number of bits, the representation cannot hold it, and the result is incorrect (it may wrap around to 0 or behave unexpectedly). A common student error is to call this a runtime crash; the CED classifies it specifically as overflow.
Related dot points
- Topic 2.2 Data Compression: compression reduces the number of bits used to store data; lossless compression preserves all information, while lossy compression discards some to save more space.
A focused answer to AP CSP Topic 2.2, covering why compression matters, lossless versus lossy compression, run-length encoding as a lossless example, the trade-offs of lossy compression for images and audio, and how to choose between them.
- Topic 2.3 Extracting Information from Data: information is extracted from data through processing, filtering, transforming and combining data sets, and correlation does not imply causation.
A focused answer to AP CSP Topic 2.3, covering the difference between data and information, processing data to find patterns and trends, filtering and transforming, metadata, combining data sets, and the limits of data including correlation versus causation.
- Topic 2.4 Using Programs with Data: programs process large data sets through cleaning, filtering, classifying and transforming data, often using lists and iteration to scale to large amounts of data.
A focused answer to AP CSP Topic 2.4, covering why programs are essential for large data sets, cleaning and classifying data, filtering with conditionals, using lists and iteration to process data at scale, and visualizing results, with worked pseudocode.
- Topic 3.2 Data Abstraction: data abstraction manages complexity by giving a collection of data a single name, most commonly using a list to represent many values as one variable.
A focused answer to AP CSP Topic 3.2, covering what data abstraction is, how a list represents many values under one name, the benefits for managing and modifying programs, the link to procedural abstraction, and why abstraction manages complexity.
- Topic 1.4 Identifying and Correcting Errors: programs contain logic, syntax, runtime and overflow errors, and programmers find and fix them by testing with carefully chosen inputs and debugging.
A focused answer to AP CSP Topic 1.4, covering logic, syntax, runtime and overflow errors, testing with chosen inputs including edge cases, debugging strategies such as tracing and adding display statements, and how to describe testing in the Create task.
Sources & how we know this
- AP Computer Science Principles Course and Exam Description — College Board (2025)