AP CSP topic 2.1
Binary Numbers
Computers store all data, including numbers, text, images, and sound, as bits, which are 0s and 1s. Binary is base 2, so each place value is a power of 2: 1, 2, 4, 8, 16, and so on. With n bits you can represent 2 to the n different values, so 8 bits (one byte) gives 256 values. Because computers use a fixed number of bits, some values cause overflow errors, and real numbers can only be stored approximately, causing round-off errors.
Binary Numbers vocabulary
- Bit: A binary digit, 0 or 1; the smallest unit of data in a computer.
- Byte: A group of 8 bits, which can represent 256 different values.
- Binary: A base-2 number system that uses only the digits 0 and 1.
- Abstraction: Hiding details to focus on what matters, such as treating a group of bits as a letter or color.
AP-style practice questions
Try each one, then open the answer. To save your progress, take this quiz in the interactive course.
1. What is the decimal (base 10) value of the binary number 1011?
- (A) 3
- (B) 11
- (C) 13
- (D) 1011
Show answer
(B) 11 1011 = 8 + 0 + 2 + 1 = 11.
2. How many different values can be represented with 5 bits?
- (A) 5
- (B) 10
- (C) 25
- (D) 32
Show answer
(D) 32 n bits represent 2^n values. 2^5 = 32.
A game stores each player's score using 4 bits, so the largest score it can store is 15.
3. A player with a score of 15 earns one more point. Which of the following is most likely to happen?
- (A) The score becomes 16
- (B) An overflow error occurs
- (C) The score is compressed
- (D) The score becomes a string
Show answer
(B) An overflow error occurs 16 needs 5 bits. With only 4 bits the value cannot be stored, causing overflow.
4. The same sequence of bits can represent a number, a letter, or a color. Which of the following explains this?
- (A) Bits are always numbers
- (B) The meaning of bits depends on how a program interprets them
- (C) Letters use different bits than numbers
- (D) Colors are not stored as bits
Show answer
(B) The meaning of bits depends on how a program interprets them Bits are an abstraction. The program decides whether they mean a number, a character, or a color.