AP CSP 2.1 Binary Numbers | Bits, Bytes, and Binary to Decimal
Binary Numbers
After this lesson, you will be able to:
- Define a bit and a byte and explain that computers represent all data as sequences of bits
- Convert a binary number to decimal by summing the place values where a 1 appears
- Convert a decimal number to binary using powers of 2 or repeated division by 2
- Explain why n bits represent 2 to the n distinct values, and relate this to overflow
- Distinguish analog from digital data and explain overflow and roundoff errors as limits of fixed bit-width
A single light switch can be off or on, which is exactly two states. String eight of those switches together and you can spell any letter, store a number up to 255, or set the shade of one pixel. Computers do not understand the number 42, a photo, or the word cat directly, yet all three end up as nothing but 0s and 1s. How can two symbols possibly be enough to represent everything a computer stores?
Bits, Bytes, and Why Two Symbols Are Enough
A bit is a binary digit: a single value that is either 0 or 1. It is the smallest unit of data a computer stores. A byte is a group of 8 bits. Computers represent all data — numbers, text, images, and sound — as sequences of bits. A photo, a song, and this sentence are all, underneath, just long strings of 0s and 1s. The meaning comes from how a program agrees to interpret those bits, not from the bits themselves.
Two symbols are enough because you combine them in a place-value system, the same idea you already use in base ten. In decimal you have ten digits and each place is worth ten times the one to its right. Binary is base 2: only two digits, and each place is worth twice the one to its right. Add more bits and you can count higher, exactly the way adding another decimal digit lets you count past 9.
Know the vocabulary cold: a bit is one 0 or 1, a byte is 8 bits, and every kind of data is stored as bits. A question that says a computer stores text or images "as binary" or "as sequences of bits" is stating a fact you are expected to already accept.
Binary Place Values and Converting to Decimal
Because binary is base 2, the place values are the powers of 2. Reading right to left they are 1, 2, 4, 8, 16, 32, 64, 128, and so on, each one double the last. To convert a binary number to decimal, write the place values above the bits and add up the place values wherever a 1 appears.
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Binary digit | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
In the row above, 1s sit in the 8, 2, and 1 columns, so the value is 8 + 2 + 1 = 11. That is how you read the binary number 1011 as decimal 11. The reverse direction, decimal to binary, is covered next.
1011 to decimal.Converting Decimal to Binary
Two reliable methods give the same answer. Pick whichever you trust under time pressure.
-
Subtract the largest power of 2. Find the biggest power of 2 that fits, put a 1 there, subtract it, and repeat with what is left. For 37: 32 fits, leaving 5; 4 fits, leaving 1; 1 fits, leaving 0. Ones go in the 32, 4, and 1 columns, giving
100101. -
Repeated division by 2. Divide by 2 and record each remainder. The remainders, read from bottom to top, are the binary digits. Dividing 37 gives remainders 1, 0, 1, 0, 0, 1 from last to first, which reads as
100101.
Check your work by converting back: 32 + 4 + 1 = 37. If the place values you marked do not add to the original decimal number, one of the bits is wrong.
With the division method, students read the remainders in the order they wrote them and get the number backwards. The correct order is bottom to top (last remainder first). Always sanity-check by adding the place values back to the original decimal.
How Many Values Can n Bits Hold?
With n bits you can represent 2 to the n distinct values. Each bit doubles the count, because every existing pattern can now end in either a 0 or a 1. So 1 bit gives 2 values, 2 bits give 4, 3 bits give 8, and 8 bits (one byte) give 2^8 = 256 values. When those 256 values are used for whole numbers starting at zero, the range is 0 to 255, not 1 to 256.
| Number of bits | Distinct values (2 to the n) |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 4 | 16 |
| 8 (one byte) | 256 |
This rule is the backbone of many exam questions. Adding a single bit does not add one more value, it doubles the number of values you can store.
Analog vs Digital
Analog data changes smoothly and continuously, with infinitely many possible values between any two points — think of a dimmer knob sliding, a real sound wave, or a shadow lengthening through the afternoon. Digital data uses discrete values: a finite set of separate steps, stored as bits. To put analog information into a computer you take samples, measuring the signal at many moments and recording each measurement as a number.
A digital version is an approximation of the analog original, like a staircase tracing a ramp. The more samples you take and the more bits you use per sample, the closer the digital copy gets to the smooth original — but with a finite number of bits it can never be a perfect match.
Match the keyword to the concept: continuous means analog, discrete or sampled means digital. Expect a question where more samples and more bits per sample yield a closer approximation of an analog signal, never an exact one.
Limits of Fixed Bit-Width: Overflow and Roundoff
Because a computer sets aside a fixed number of bits for a value, some numbers simply do not fit, and the framework names two specific errors that result.
- Overflow error: a value is too large to represent in the available bits. With 8 bits the largest whole number is 255; try to store 256 and there is no room, so the result is wrong.
-
Roundoff error: a value cannot be stored exactly and must be approximated or rounded. Many real numbers, such as the result of
1 / 3, would need infinitely many digits, so a fixed number of bits can only hold a rounded version.
The clean split: overflow is about a number being too big to fit at all; roundoff is about a number being impossible to store precisely, so it is stored close-but-not-exact. Both come from the same root cause, a finite number of bits.
Do not swap the two. If a program adds 1 to the largest value a variable can hold and gets a nonsense result, that is overflow. If a program stores 0.1 or 1/3 and later the arithmetic is slightly off, that is roundoff. "Too large to represent" is overflow; "cannot be represented exactly" is roundoff.
Many Representations, Real Tradeoffs
The same information can be represented in more than one way, and the choice has consequences. The number eleven can be written as decimal 11 or binary 1011; both mean the same quantity. Using more bits per value widens the range you can store and reduces overflow and roundoff, but it also uses more memory and storage. Representations are chosen by weighing these tradeoffs, which is a theme you will see again in data compression.
💡 See it in action
How Binary Is Tested on the Exam
Binary number representation is multiple-choice material, not a skill you demonstrate on the Create Performance Task. You will not hand-convert numbers inside your Create Task program; instead the end-of-course multiple-choice exam asks you to convert between binary and decimal, apply the 2 to the n rule, and tell overflow apart from roundoff. Treat this as fast, high-confidence points.
Quick strategy for the exam room:
- Write the place values first. Jot 128 64 32 16 8 4 2 1 across the top and line the bits up underneath. For binary to decimal, add the place values under each 1.
- For decimal to binary, subtract the largest power of 2 that fits, mark a 1, and repeat with the remainder.
- Always check by converting back. Add your marked place values; they must equal the original decimal number.
- Sort the error type by keyword. "Too large to store" is overflow; "cannot be stored exactly" is roundoff.
Get a free AP CSP question every day
Join 3,000+ students. Daily practice, study tips, and exam strategies.
What is the decimal value of the binary number 1101?
What is the binary representation of the decimal number 37?
Consider these statements about how computers store data:
- I. A byte consists of 8 bits.
- II. With n bits a computer can represent 2 to the n distinct values.
- III. Text and images are stored as sequences of bits, just like numbers.
A program uses a fixed number of bits for each whole number. It repeatedly adds 1 to a variable that already holds the largest value those bits can store, and the next result is a wrong, much smaller number. Which error does this best illustrate?
A variable is stored using 8 bits and is used to hold whole numbers starting at 0. Which statement about this variable is correct?
An analog sound wave is recorded by measuring its height many times per second and storing each measurement as a number. Which statement best describes this digital recording?
Binary Conversion Race
AP CSP • Big Idea 2, Topic 2.1 - binary place value & decimal↔binary conversion.
How to play: beat the clock. Build numbers by toggling bits, or read a bit pattern and type its value. Correct answers grow your streak for bonus points.
Ready to race?
60 seconds. Two round types alternate: Build the number and Read the bits.
The place-value header (128 64 32 16 8 4 2 1) stays on screen the whole time to guide you.
Make this decimal in binary:
Time!
Nice work!
Frequently Asked Questions
🔗 Continue studying
Binary is where students either click or freeze, so drill the place-value strip until conversions are automatic, then time them with the Binary Conversion Race game before the exam. The overflow versus roundoff distinction is a reliable point students miss, so anchor it with a keyword sort: too large to fit means overflow, cannot be stored exactly means roundoff. The Superpack includes conversion worksheets and an analog-to-digital sampling demo. View what's included →
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]