AP CSP
2Big Idea 2: Data
AP CSP topic 2.1

Binary Numbers

1011AI

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.

Picture it1280·641+64321+32160·81+841+420·11+1= 109
Place values in binary double from right to left. 01101101 = 64 + 32 + 8 + 4 + 1 = 109.

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.

Skill: Code Analysis

1. What is the decimal (base 10) value of the binary number 1011?

  1. (A) 3
  2. (B) 11
  3. (C) 13
  4. (D) 1011
Show answer

(B) 11 1011 = 8 + 0 + 2 + 1 = 11.

Skill: Code Analysis

2. How many different values can be represented with 5 bits?

  1. (A) 5
  2. (B) 10
  3. (C) 25
  4. (D) 32
Show answer

(D) 32 n bits represent 2^n values. 2^5 = 32.

Skill: Abstraction in Program Development
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?

  1. (A) The score becomes 16
  2. (B) An overflow error occurs
  3. (C) The score is compressed
  4. (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.

Skill: Abstraction in Program Development

4. The same sequence of bits can represent a number, a letter, or a color. Which of the following explains this?

  1. (A) Bits are always numbers
  2. (B) The meaning of bits depends on how a program interprets them
  3. (C) Letters use different bits than numbers
  4. (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.

Open 2.1 in the interactive course