SECTION 1
Historical Context & Motivation
The idea of representing quantities with only two symbols predates modern computing by centuries. Long before transistors and silicon chips, mathematicians recognized that any number expressible in our familiar base-10 (decimal) system could equivalently be written in base-2 (binary) — a system requiring only the digits 0 and 1. This insight became the cornerstone of digital computing because electronic circuits naturally distinguish between two voltage states: high and low, on and off, true and false. The elegance of binary lies in its alignment with the physical properties of hardware: a single binary digit, or bit, maps directly to the smallest unit of information a machine can store.
1679 • Leibniz's Binary Arithmetic
1854 • Boole's Algebra of Logic
1937 • Shannon's Master's Thesis
1945 • Von Neumann Architecture
The central question this lesson addresses is deceptively simple: how does a machine that recognizes only two electrical states represent the vast universe of numbers, text, images, and sound? The answer begins with understanding positional notation in base-2 and recognizing that every piece of digital data — from a single character to a streaming video — ultimately reduces to sequences of binary digits.
SECTION 2
Core Principles & Definitions
Binary is a positional number system — the value of each digit depends on its position within the number, just as in decimal. In decimal, positions correspond to powers of 10; in binary, positions correspond to powers of 2. Understanding this single structural parallel unlocks nearly every conversion and arithmetic operation you will need for the AP exam.
Bit
Byte
Place Value (Powers of 2)
Overflow
SECTION 3
Visual Explanation — Place Value Diagram
The place-value diagram above makes the conversion algorithm explicit. Starting from the leftmost bit (the most significant bit) and moving right to the least significant bit, you multiply each digit by the corresponding power of 2 and sum the products. Any position holding a 0 contributes zero to the total, so only the 1-bits matter. This direct mapping between bit position and power of 2 is the conceptual key to every binary-to-decimal conversion.
SECTION 4
Mathematical Framework
BINARY TO DECIMAL CONVERSION
where V is the decimal value, n is the number of bits, and bᵢ ∈ {0, 1} is the digit at position i.
RANGE OF AN N-BIT UNSIGNED INTEGER
An n-bit binary number can represent 2ⁿ distinct values. For example, 8 bits represent 0 through 255, and 16 bits represent 0 through 65,535.
DECIMAL TO BINARY (REPEATED DIVISION)
At each step, divide the quotient by 2. The remainder (0 or 1) becomes the next bit, starting at the least significant position. Continue until the quotient reaches 0.
Binary arithmetic follows the same rules as decimal arithmetic, with a simpler addition table: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10 (i.e., 0 with a carry of 1). When carries cascade—as in 1111 + 0001—every bit position generates a carry, and the result overflows if there are not enough bits to hold the final carry. Recognizing overflow conditions is an important exam skill: adding two n-bit numbers can produce a result requiring n + 1 bits.
SECTION 5
Detailed Breakdown — Conversion Methods
The repeated-division algorithm is systematic and mechanical, but for numbers that are close to powers of 2 or that you can decompose by inspection, a subtraction method is often faster. Start with the largest power of 2 that does not exceed the target, place a 1 in that position, subtract, and repeat with the remainder. For example, 200 = 128 + 64 + 8, so 200₁₀ = 11001000₂. Both approaches yield the same result; familiarity with both lets you choose the quicker path on a timed exam.
| Decimal | Binary | Bit Count |
|---|---|---|
| 0 | 0 | 1 |
| 7 | 111 | 3 |
| 15 | 1111 | 4 |
| 16 | 10000 | 5 |
| 255 | 11111111 | 8 |
| 256 | 100000000 | 9 |
Common decimal-to-binary reference values
SECTION 6
Worked Example — Binary Addition & Overflow
Worked example
- 1
Step 1 — Interpret the operands
Convert each binary number to decimal to verify your result later. 10110011₂ = 128 + 32 + 16 + 2 + 1 = 179. 01101010₂ = 64 + 32 + 8 + 2 = 106.179 + 106 = 285 (expected decimal sum) - 2
Step 2 — Align and add column by column
Starting from the rightmost bit (b₀), add corresponding digits plus any carry from the previous column. In the b₀ column: 1 + 0 = 1, carry = 0. In b₁: 1 + 1 = 0, carry = 1. Continue across all eight columns, propagating carries as needed. - 3
Step 3 — Record the result
The column-by-column addition produces: carry out = 1, and the 8-bit result = 00011101₂. The carry out of 1 indicates that the true sum requires 9 bits: 100011101₂ = 285.Full 9-bit result: 100011101₂ = 285₁₀ - 4
Step 4 — Detect overflow
Because the system is limited to 8 bits, the carry bit is lost. The stored value would be 00011101₂ = 29, not 285. This is a classic overflow error — the result exceeds the maximum 8-bit unsigned value of 255.Overflow detected: 8-bit result wraps to 29
SECTION 7
Number Bases Compared — Binary, Decimal & Hexadecimal
| Property | Binary (Base 2) | Decimal (Base 10) | Hexadecimal (Base 16) |
|---|---|---|---|
| Digits used | 0, 1 | 0–9 | 0–9, A–F |
| Place value factor | × 2 | × 10 | × 16 |
| Representation of 255 | 11111111 | 255 | FF |
| Primary use | Hardware / logic gates | Human communication | Compact binary shorthand (colors, memory addresses) |
| Strengths | Maps directly to electrical states; simplest arithmetic rules | Intuitive for humans; familiar | Each hex digit = 4 bits; very compact |
| Limitations | Long strings for large values; hard for humans to read | No direct hardware analog | Less intuitive than decimal; extra letter-digits needed |
SECTION 8
Connection to Advanced Representations
Unsigned binary numbers, which represent only non-negative integers, are the foundation upon which more sophisticated data representations are built. The AP CSP curriculum expects you to recognize that binary encoding extends far beyond simple counting. Numbers with fractional parts, negative numbers, characters, colors, and audio samples all rely on agreed-upon abstractions layered on top of binary sequences.
| Data Type | Binary Mechanism | Key Idea |
|---|---|---|
| Negative integers | Two's complement: flip bits and add 1 | The MSB becomes a sign bit; range shifts to −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 |
| Real numbers | Floating-point (IEEE 754): sign + exponent + mantissa | Finite bits approximate infinite precision; rounding errors are inherent |
| Text characters | ASCII (7 bits) / Unicode (up to 32 bits) | Each character is assigned a unique numeric code expressed in binary |
| Colors | RGB: 8 bits per channel (24 bits total) | Over 16 million colors from combinations of red, green, and blue |
The overarching principle is that binary alone does not inherently mean anything — meaning arises from the abstraction layer that interprets the bits. The same 8-bit sequence 01000001 could represent the unsigned integer 65, the ASCII character 'A', or part of a pixel's color, depending on context. This idea — that data requires agreed-upon encoding schemes to be meaningful — is a recurring theme throughout AP Computer Science Principles.
SECTION 9
Practice Problems
Question 1: CONCEPTUAL
- A. Binary requires fewer digits than decimal to represent the same number.
- B. Electronic circuits can reliably distinguish between two voltage states (high and low), making binary a natural fit for hardware.
- C. Binary is the only number system that supports arithmetic operations like addition and subtraction.
- D. Humans find binary easier to read and compute with than decimal.
Show answer (B)
Question 2: BASIC CALCULATION
- A. 198
- B. 214
- C. 218
- D. 204
Show answer (B)
Question 3: INTERMEDIATE
- A. The largest value that can be represented is 16.
- B. Adding 1 to 1111₂ produces an overflow.
- C. There are exactly 16 distinct values that can be represented.
- D. The binary representation of 9 requires 5 bits and cannot be stored.
Show answer (B,C)
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING