Binary Number
A binary number is one where each of the digits can only be a 0 or a 1. The values will double with each position. So the left-most digit is 0 or 1, the second bit is 0 or 2, the third is 0 or 4 and the fourth is 0 or 8. You can generate any number from 0 to 15 by adding the values.
Prompt
Create a simulation of a 4-bit binary number.
Add buttons that toggle each of the four bits.
Add a text output that shows the decimal equivalent of the binary number.
Sample Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
Learnings from The Response
- How to set up an array of buttons each with different actions
- How to use the pow(2, i) to convert a binary to decimal value
- How to setup a tobbleBit(index) function using the
?
and:
syntax
Lesson Plan
Objective:
Students will understand the binary number system and how it is used in computer science. They will learn to convert binary numbers to decimal numbers and vice versa.
Grade Level: 9th Grade
Duration: 1-2 class periods (45-90 minutes)
Materials:
- Computers with internet access (or offline environment set up with p5.js).
- Projector to demonstrate the simulation.
- Link to the simulation.
- Worksheets or online notebooks for binary-to-decimal conversion exercises.
- Whiteboard and markers.
Lesson Outline:
-
Introduction to Binary Numbers (15 minutes):
-
Begin with a discussion on number systems, focusing on the decimal system.
- Introduce the binary number system, explaining its base-2 nature.
-
Discuss the significance of binary numbers in computer science.
-
Demonstration of the Simulation (10 minutes):
-
Project the simulation on the screen.
- Explain the interface, pointing out the bits, their significance, and the decimal conversion.
-
Demonstrate toggling the bits and observing the decimal output.
-
Interactive Session with Simulation (20 minutes):
-
Allow students to experiment with the simulation on their computers.
- Encourage them to predict the decimal output before toggling the bits.
-
Facilitate a discussion about their observations and insights.
-
Binary to Decimal Conversion Exercise (15 minutes):
-
Distribute worksheets with binary numbers.
- Instruct students to convert them to decimal numbers using the simulation as a reference.
-
Review the answers as a class, discussing any common errors or misconceptions.
-
Group Activity: Real-World Applications (15-30 minutes):
-
Divide students into small groups.
- Assign each group to research and present a short explanation about a real-world application of binary numbers (e.g., digital storage, computer processors).
-
Facilitate a class discussion on these applications, linking them back to the simulation.
-
Wrap-up and Reflection (5-10 minutes):
-
Summarize key takeaways from the lesson.
- Encourage students to reflect on what they learned and how they might see binary numbers in their daily lives.
- Answer any remaining questions.
Assessment
- Evaluate students based on their participation in activities and discussions.
- Review their worksheets for accuracy in binary to decimal conversion.
- Assess group presentations for understanding of real-world applications.
Extension Activities
- Extend the simulation to be 8, 16, 32 and 64 bits
- Discuss what the shift-left and shift-right functions will do. Hint: how would you double the number?
- Introduce the concept of hexadecimal numbers and how they relate to binary and decimal systems.
- Create a project where students develop their own simple binary-based simulations or games using p5.js.
- Discuss the process of adding binary numbers.
References
- ChatGPT Transcript - this demonstrates the iterative nature of prompting including giving up and fixing the code myself after multiple attempts.