At My Fingertips
The CS Unplugged collection includes a great lesson introducing binary numbers.
Assume you want to represent numbers with cards. Here we have 8 cards. You see the front side of the rightmost card, and the back sides of the seven other cards.
You see one dot (on the rightmost card). Because you see one dot, this configuration represents the number 1.
Here is how you would represent the number 2:
The card with its front-side visible contains two dots.
The answer is 4. Really?? Yes!
It contains 8 dots.
Here are all our eight cards with their front side showing:
Yes! You double the number! Each card has twice as many dots as its right neighbor. Each card represents a power of two:
We know how to represent the numbers 1, 2, 4, 8, ... (the powers of two). But how to represent other natural numbers?
You show the dots of two of the cards: the card with 1 dot, and the card with 2 dots:
Here is how:
This scheme allows you to represent numbers also between the powers of two.
Each card represents a bit. A bit can be on (dots showing) or off (dots hidden). Eight bits correspond to a byte. So our eight cards represent one byte.
You would show the dots on all cards:
You see a total of 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255 dots.
Thus, the largest number you can represent with eight bits is 255.
Yes, the smallest number is 0. You can flip all cards over so none of them shows its dots.
Now let's write a program that can generate these cards.
Each graphic seems to consist of a white sheet. The square area at the top of the sheet contains the dots, the band at the bottom of the sheet contains a decimal number representing the dot count.
The number of dots is always a power of 2.
The aspect ratio of the sheet is 1 : sqrt(2)
.
The cards differ in the number of dots they represent.
If the number of dots is a power of 4 (e.g., 1, 4, 16, ...), then the dots are arranged into a square. Otherwise the dots are arranged into a rectangle, with twice as many rows than columns.
Hint: Divide the square into smaller squares. You may want to do that recursively. Place the dots inside the smallest squares. The diameter of each dot is 80% of side of the smallest square.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Binary Numbers
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version b744b47 (Tue, 08 Oct 2024 16:30:14 GMT)