Chapter 2.9 - Binary Numbers

Time Estimate: 90 minutes

2.9.1. Introduction and Goals

Binary numbers are used to represent all computer data. That is, everything is in 0s and 1s. In this lesson, we'll explore the binary number system and learn how to count in binary.

Learning Objectives: I will learn to

  • Explain how data can be represented in bits

  • Explain the consequences of using bits to store data

  • Calculate the binary (base 2) equivalent of a positive integer (base 10) and vice versa

  • Compare and order binary numbers

Language Objectives: I will be able to

  • Describe the reasons why computers use the binary number system using target vocabulary, supporting details, and examples

  • Explain the steps for converting between the decimal and binary number systems using key vocabulary, such as binary, and positional number system, out loud and in writing, with the support of vocabulary notesarrow-up-right from this lesson

2.9.2. Learning Activities

There are only 10 types of people in the world. Those who understand binary and those who don't!

Lecture

Binary To Decimalarrow-up-right

Video: Counting in Binary

Do you get the joke at the beginning of this lesson? If not, you'll certainly get it after watching this video from the Computer Science Unpluggedarrow-up-right, which illustrates how the binary number system works.

ENGLISH Computer Science Unplugged - Part 1 Binary - 2005arrow-up-right

Activities: Decimal and Binary Odometers

Your teacher may choose to have you do some or all of the activities below:

  1. Your class can act out the video above by printing and using the following Binary Dot Cardsarrow-up-right. Have 5 students volunteer to hold the 5 cards at the front of the class. Have them flip the cards randomly and see if the class can figure out the binary and the corresponding decimal number they make by counting the dots. See if the 5 volunteers can count up from 0 to 11111. What's the largest number that you can make with the 5 binary digits? You may want to return to this activity when you get to the converting binary to decimal and converting decimal to binary sections below.

  2. As you saw in the video, the children together were simulating a binary odometer to count in base 2. Humans use the decimal number system, counting in base 10, probably because we have 10 fingers, but computer circuits only have 2 states, on and off, and so use the binary (base 2) number system. A binary odometer is similar to a decimal (base 10) odometer, like the one we have in our cars, except it only has two digits. And the rightmost digit is the 1s place. The digit to its left is the 2s place, and then comes the 4s place, and so on. To try this yourself, use a piece of paper or the first table in this binary/hex worksheetarrow-up-right and the odometer approach to write out the values of the first 16 binary numbers. Remember, you can only use 0's and 1's. HINT: You'll need 4 digits (bits) to represent the numbers 0 through 15 in binary, so write the value 0 as 0000. If you get stuck or to check your answer, use this binary odometer app for help or to check your answer:

Q-1: What's the largest number that can be represented in 4bits?

A. 16

B. 15

C. 5

D. 12

Q-2: An overflow error occurs when there aren't enough bits to represent a given number. Which of the following would cause an overflow error to occur? (Choose all that apply)

A. Trying to represent 31 in 5 bits.

B. Trying to represent 16 bits in 4 bits.

C. Trying to represent 15 in 4 bits.

D. Trying to represent 32 in 5 bits.

Q-3: True or False. Using a fixed number of bits to represent numbers limits the range of values and hence limits the range of problems that can be solved with that representation.

A. True

B. False

Video: Converting Binary to Decimal

As you saw in the video, the binary number system is a positional number system. The value of a particular digit depends on its place. After you've watched the video, there's an activity to give you some practice at converting binary (base 2) to decimal (base 10).

In this next short video, you'll learn a simple algorithm for converting a binary number into a decimal.

Binary To Decimalarrow-up-right

Activities: Converting Binary to Decimal

Your teacher may choose to have you do some or all of the activities below:

  1. Your class can act out binary conversion using the Binary Dot Cardsarrow-up-right. Have the 5 students flip the dot cards randomly to make a binary number, and have the class figure out what decimal number it is.

  2. Try the following Binary Converter. In pairs, have one partner click on the binary digits below to create a binary number, and have the other partner figure out the number as a decimal number (click on the ? button to check your the answer). You can also use the paper binary converter tool at the bottom of the binary/hex worksheetarrow-up-right that you may have printed out in the last activity. Make sure it is printed double-sided and cut the 1's into tabs that can be flipped over to cover the 0's.

  3. Use the algorithm described in the video with this interactive Khan Academy component to convert binary to decimal.

Binary Converter arrow-up-rightActivity: 2.9.2.7 Khanex (khanex1)

Video: Converting Decimal to Binary

You can use a similar algorithm to convert decimal numbers into binary. This next short video shows you how.

Decimal to Binaryarrow-up-right arrow-up-rightActivity: 2.9.2.8 YouTube (cSCWnI7JMSU)

Activities: Converting Decimal to Binary

Your teacher may choose to have you do some or all of the activities below:

  1. Your class can act out binary conversion using the Binary Dot Cardsarrow-up-right. Have the class call out a decimal number, and have the 5 students with the binary dot cards figure out the equivalent binary number to show.

  2. Try the Binary Converter in reverse. In pairs, have one partner call out a number in base 10 from 0 to 255 (remember that the highest number that you can make with x bits is 2x - 1), and have the other partner click on the binary digits below to figure out that number in binary.

  3. Complete the first two columns on the second page of the binary/hex worksheetarrow-up-right that you may have printed out in the last activity. (Skip over rows that do not have anything written in the decimal or binary columns. You will finish the hex column of this worksheet in the next section.) If you print this out double-sided, you can cut the 1's into tabs and flip them over to create a paper binary converter tool to help you with your calculations.

  4. Use the algorithm described in the video with this interactive Khan Academy component to convert a decimal to binary.

Decimal To Binaryarrow-up-right Activity: 2.9.2.9 Khanex (khanex2)

Everything in a computer is represented with sequences of bits, 0’s and 1’s. There are some consequences of using bits to represent data, though. How do you think repeating decimal (real) numbers like 3.33333333… are stored in a computer’s memory? Would it fit in memory if it were an infinitely repeating decimal? Since the memory would not be able to hold an infinitely repeating number like this, computers round off repeating decimals after a fixed number of bits and only hold their approximate values in memory. Even with integer numbers, the memory will limit the size of the integer. The fixed number of bits used to represent numbers limits the range of values and mathematical operations on those values, and can even cause errors such as overflow or rounding errors. An overflow error occurs when a computer attempts to handle a number that is larger than the memory it has available. Even modern computers can occasionally have an overflow error when the computer attempts to handle a very large number that is outside of the defined range of values that can be represented. In many programming languages, integer numbers are limited to a size of 4 bytes (32 bits, where each byte is 8 bits) in memory, and real numbers with decimal points to 8 bytes. Languages like Thunkable and the AP pseudocode only limit the size of the data by the size of the computer’s memory.

Other Number Systems

One problem with binary numbers is that it takes lots of digits to represent relatively small numbers. For example, a number like 1 million would require 20 binary digits: 11110100001001000000. In computer science, we also use the octal (base 8) and hexadecimal (base 16) number system, which uses the digits 0-9 as well as the letters A-F to represent the decimal numbers 0-15. Each 4 binary bits can be replaced by 1 hex digit. The AP CSP exam no longer covers the hexadecimal number system, but if you're curious, you can learn more about octal and hex in the links provided in the Still Curious section below.

Decimal

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Hexadecimal

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Binary

0

1

10

11

100

101

110

111

1000

1001

1010

1011

1100

1101

1110

1111

Did you know that the Ancient Maya Civilization used a base 20 number system with just 3 symbols for 0, 1, and 5? Try the Maya Math Gamearrow-up-right.

2.9.3. Summary

In this lesson, you learned how to:

Learning Objective CRD-2.I.a: For errors in an algorithm or program: a. Identify the error.

Learning Objective CRD-2.I.b: For errors in an algorithm or program: b. Correct the error.

  • An overflow error is an error that occurs when a computer attempts to handle a number that is outside of the defined range of values.

Learning Objective DAT-1.A: Explain how data can be represented using bits.

  • Bits are grouped to represent abstractions. These abstractions include, but are not limited to, numbers, characters, and color.

Learning Objective DAT-1.B: Explain the consequences of using bits to represent data.

  • In many programming languages, integers are represented by a fixed number of bits, which limits the range of integer values and mathematical operations on those values. This limitation can result in overflow or other errors.

  • Other programming languages provide an abstraction through which the size of representable integers is limited only by the size of the computer's memory; this is the case for the language defined in the exam reference sheet.

  • In programming languages, the fixed number of bits used to represent real numbers limits the range and mathematical operations on these values; this limitation can result in round-off and other errors. Some real numbers are represented as approximations in computer storage. EXCLUSION STATEMENT (EK DAT-1.B.3): Specific range limitations for real numbers are outside the scope of this course and the AP Exam.

Learning Objective DAT-1.C.a: For binary numbers: a. Calculate the binary (base 2) equivalent of a positive integer (base 10) and vice versa.

Learning Objective DAT-1.C.b: For binary numbers: b. Compare and order binary numbers.

  • Number bases, including binary and decimal, are used to represent data.

  • Binary (base 2) uses only combinations of the digits zero and one.

  • Decimal (base 10) uses only combinations of the digits 0 – 9.

  • As with decimal, a digit’s position in the binary sequence determines its numeric value. The numeric value is equal to the bit’s value (0 or 1) multiplied by the place value of its position.

  • The place value of each position is determined by the base raised to the power of the position. Positions are numbered starting at the rightmost position with 0 and increasing by 1 for each subsequent position to the left.

2.9.4. Still Curious?

2.9.5. Self-Check

Vocabulary

Here is a table of the technical terms we've introduced in this lesson. Hover over the terms to review the definitions.

binary sequence

bit

base

positional number system

decimal number system

binary number system

octal number system

hexadecimal number system

overflow error

Check Your Understanding

Complete the following self-check exercises.

Q-1: AP 2021 Sample Question: Each student who enrolls at a school is assigned a unique ID number, which is stored as a binary number. The ID numbers increase sequentially by 1 with each newly enrolled student. If the ID number assigned to the last student who enrolled was the binary number 1001 0011, what binary number will be assigned to the next student who enrolls?

A. 1001 0111

B. 1001 0100

C. 1101 0100

D. 1101 0111

Reflection: For Your Portfolio

Answer the following portfolio reflection questions as directed by your instructor. Questions are also available in this Google Docarrow-up-right, where you may use File > Make a Copy to make your own editable copy.

Last updated