Students compare and order binary numbers. (DAT-1.C)
Students will explain the consequences of using bits to represent data. (DAT-1.B)
Students will demonstrate that bits can represent numbers. (DAT-1.A.6)
Bits can be grouped together to represent different types of data. In this section, we will focus on how bits can be used to represent numbers. They will practice their binary conversion skills by putting binary numbers in order. Students will also learn about overflow errors. The lesson begins with a warm up review activity in which students and their partner will take a list of binary numbers and put them in order. The teacher will lead the students through discussion and demonstration of the relationship between the number of bits and the values that can be represented. Hexadecimal number conversions are no longer part of the APCSP course requirements. However, we have included an optional hexadecimal activity to illustrate another number system representation.
Activity 4.5.1 (10 minutes)
Student and partner put the binary values in order from least to greatest.
Discussion points:
How did you solve this? Most will say that they converted to decimal and then put in order. However, other students may have different methods and it is beneficial to have them share.
Do you need the leading zeros (on the left)? Will removing them change the value? Could that have sped up the process?
Activity 4.5.2 (budget 15 minutes)
Display the binary flippy do from Section 4.4. . Pose the following question to students and give 1 - 2 minutes for them to silently think about it:
“What is the relationship between the binary flippy do and a byte?”
The “binary flippy do” tool can represent 8 bits or a byte.
Then ask…if I have a byte, what is the largest decimal value that I can store in it? Answer: 255 If all 8 its were 1’s, the decimal equivalent would be 255.
How many different decimal values can a byte store? Answer: 256 values, range 0 - 255.
What if I only have 6 bits? What is the largest value? Answer: 63
If I have 6 bits, how many values can be stored? Answer: 64 values, range of 0 - 63
Ask students a few more questions like those in the previous step. Students can use their own flippy-do tools to answer.
Now that students are comfortable with the relationship between the number of bits & largest decimal value or number of values, pose this question…
Assume that I have a byte of storage (8 bits). I need to store the value 256. Can I do it?
Answer: No, I will need one more bit.
If I add another bit so that I can store the value 256, what happens to the binary values stored in the original byte?
Answer: They look like all zeros. Think about a car odometer. If I am at 999 miles and I go one further, the odometer rolls over to 1000. The first three place value holders are all zeros and an additional place value has been added for the 1. In computer storage capacity, 255 in binary is 11111111. When we want to go to one higher (256), it “rolls over” to look like: 100000000. The first 8 place value holders (the byte) are all zeros so is this a value of 0 for the byte or does the computer know to include the extra bit and have a value of 256? This concept is call the “overflow error” and it results when there is a fixed number of bits to store a value. This is all the students need to know for the scope of this content in APCSP. Different operating systems handle this situation differently but our students are not expected to know the details of how this works.
There are additional practice questions on these topics in the secure practice exams in the AP course audit.
Activity 4.5.3 (budget 15 minutes)
Hexadecimal conversions are no longer a required element in APCSP. However, understanding that the conversions process algorithm is the same for differing number systems is a good skill for students to have. They just need to know the base of the number system. Then they can set up a place value chart and go through the same process for conversions.
Hexadecimal is a base 16 number system. It uses the digits 0 - 9 and the letters A - F. It allows much larger values to be represented. Common uses for hexadecimal values are color values (#FFFFFF is white and #000000 is black. All other color values fall between) and the IPv6 addressing system for IP addresses.
Follow this lesson to introduce students to hexadecimal conversions.