AP® Computer Science Principles Practice Questions
Work through AP Computer Science Principles practice questions unit by unit, then check each answer against a worked solution.
Free · no sign-up Open questions need no account. Sign up or log in to open the rest.
Question 42
Question 43
Question 44
Question 45
Question 46
Question 47
In a certain computer program, two positive integers are added together, resulting in an overflow error. Which of the following best explains why the error occurs?
Main Solution
Correct Answer: C
An overflow error occurs in computing when the result of an arithmetic operation exceeds the maximum value that can be stored in the allocated number of bits. Because computers use a fixed number of bits (e.g., 32-bit or 64-bit integers) to represent integers, there is a finite maximum value that can be represented. When two positive integers are added and their sum surpasses this maximum representable value, the result cannot be stored correctly, causing an overflow error.
Option C directly and accurately describes this mechanism: the fixed-bit representation imposes a ceiling on representable values, and exceeding that ceiling produces the overflow.
Teacher Explanation
This question tests students' understanding of integer overflow as a consequence of fixed-width binary representation. In AP CSP, students should know that all data in a computer is represented using a finite number of bits, which limits the range of values that can be stored. When an arithmetic result exceeds that range, an overflow error results. This is distinct from floating-point precision errors (option B) or undecidability (option A).
Education Coach Advice
On the AP CSP exam, carefully distinguish between overflow errors (integer result too large for fixed bits) and roundoff/precision errors (floating-point approximation). Key phrase in the question: "two positive integers are added" and "overflow error" — this points directly to the fixed-bit integer representation limit. Eliminate options about undecidability (a logic/computability concept) and floating-point (a different representation type) first.
Traps
Most appealing wrong answer: B. Students may confuse overflow with floating-point precision errors. Floating-point representation causes rounding/precision issues, not overflow errors for integer addition. Overflow is specifically about exceeding the maximum value storable in a fixed number of bits for integers, not about approximation in floating-point. Option D is also tempting but is incorrect because integers are representable exactly in binary; the issue is the size limit, not approximation.
Answer images
Question 48
A color in a computing application is represented by an RGB triplet that describes the amount of red, green, and blue, respectively, used to create the desired color. A selection of colors and their corresponding RGB triplets are shown in the following table. Each value is represented in decimal (base 10).
| Color Name | RGB Triplet |
|---|---|
| indigo | (75, 0, 130) |
| ivory | (255, 255, 240) |
| light pink | (255, 182, 193) |
| light yellow | (255, 255, 224) |
| magenta | (255, 0, 255) |
| neutral gray | (127, 127, 112) |
| pale yellow | (255, 255, 160) |
| vivid yellow | (255, 255, 14) |
According to information in the table, what color is represented by the binary RGB triplet (11111111, 11111111, 11110000) ?
Main Solution
To solve this problem, convert each binary value in the triplet (11111111, 11111111, 11110000) to decimal (base 10):
- 11111111 in binary: \ \(2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255\)
- 11111111 in binary: \ \(255\) (same as above)
- 11110000 in binary: \ \(2^7 + 2^6 + 2^5 + 2^4 = 128 + 64 + 32 + 16 = 240\)
So the decimal RGB triplet is (255, 255, 240).
Looking up (255, 255, 240) in the table, this matches ivory.
The correct answer is A) Ivory.
Teacher Explanation
This question tests students' ability to convert binary (base 2) numbers to decimal (base 10) and then match the result to a table entry. The key skill is recognizing that 11111111 = 255 and 11110000 = 240, yielding the triplet (255, 255, 240) which corresponds to ivory.
Education Coach Advice
When converting binary to decimal on the AP exam, write out the place values (128, 64, 32, 16, 8, 4, 2, 1) above each bit and add only those with a 1. For 11110000: the four leftmost bits are 1, giving 128+64+32+16 = 240. Double-check by counting the number of 1s and 0s — there should be exactly 8 bits total.
Traps
A common trap is confusing 11110000 with other values. Students might miscount the bits and arrive at 224 (which is 11100000), leading them to choose B) Light yellow (255, 255, 224). Another trap is misreading 11110000 as 14 (which is 00001110), leading to D) Vivid yellow (255, 255, 14). Careful bit-by-bit conversion is essential.
Answer images
Question 49
A color in a computing application is represented by an RGB triplet that describes the amount of red, green, and blue, respectively, used to create the desired color. A selection of colors and their corresponding RGB triplets are shown in the following table. Each value is represented in decimal (base 10).
| Color Name | RGB Triplet |
|---|---|
| indigo | (75, 0, 130) |
| ivory | (255, 255, 240) |
| light pink | (255, 182, 193) |
| light yellow | (255, 255, 224) |
| magenta | (255, 0, 255) |
| neutral gray | (127, 127, 112) |
| pale yellow | (255, 255, 160) |
| vivid yellow | (255, 255, 14) |
What is the binary RGB triplet for the color indigo?
Main Solution
The RGB triplet for indigo is (75, 0, 130) in decimal. We need to convert each value to 8-bit binary.
Converting 75 to binary:
\(75 = 64 + 8 + 2 + 1 = 2^6 + 2^3 + 2^1 + 2^0\)
\(75_{10} = 01001011_2\)
Verification: \(0 \cdot 128 + 1 \cdot 64 + 0 \cdot 32 + 0 \cdot 16 + 1 \cdot 8 + 0 \cdot 4 + 1 \cdot 2 + 1 \cdot 1 = 64 + 8 + 2 + 1 = 75\) ✓
Converting 0 to binary:
\(0_{10} = 00000000_2\)
Converting 130 to binary:
\(130 = 128 + 2 = 2^7 + 2^1\)
\(130_{10} = 10000010_2\)
Verification: \(1 \cdot 128 + 0 \cdot 64 + 0 \cdot 32 + 0 \cdot 16 + 0 \cdot 8 + 0 \cdot 4 + 1 \cdot 2 + 0 \cdot 1 = 128 + 2 = 130\) ✓
Therefore, the binary RGB triplet for indigo is (01001011, 00000000, 10000010), which is option C.
Teacher Explanation
This question tests students' ability to convert decimal integers to 8-bit binary representations. The key skill is performing repeated division by 2 (or recognizing powers of 2) for each component of the RGB triplet. Students must correctly convert 75 → 01001011 and 130 → 10000010. The distractors use 00100101 (which is 37, not 75) and 01000001 (which is 65, not 130), targeting students who make arithmetic errors in the conversion process.
Education Coach Advice
AP Exam Strategy: When converting decimal to binary, always start by identifying the largest power of 2 that fits into the number. For 8-bit representations, check if the number is ≥ 128 first — if so, the leftmost bit is 1. For 130: 130 ≥ 128, so bit 7 = 1; 130 − 128 = 2; 2 = 2¹, so bit 1 = 1. Result: 10000010. Always verify by summing the place values back to the original decimal to catch errors before selecting your answer.
Traps
Common traps:
- Option A (00100101, 00000000, 10000010): Uses 00100101 for the red component. 00100101 = 37 in decimal, not 75. Students may make an error when converting 75, perhaps halving it incorrectly.
- Option B (00100101, 00000000, 01000001): Gets both the red and blue components wrong. 01000001 = 65, not 130.
- Option D (01001011, 00000000, 01000001): Gets the red component correct (75 = 01001011) but converts 130 incorrectly as 01000001 (= 65). Students may forget that 130 > 128, so the leading bit must be 1.
Answer images
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

