Docs CS Intro Binary Activity Activity: Binary transmogrifier Guide the students through building a binary transmogrifier converter that converts between binary base-2 enter binar decimal base numbers. Let them figure out a pattern that will allow them to do the conversion on the fly.
Create the Variables Students will need to create a number variable to hold the running decimal total. They should also create a string variable to hold the current binary number. From the Variables menu, make and name these two variables: decimal, binary. Initialize the Variables When the program starts up, you should initialize your variables to starting values.
Binary strings are distinguished from character strings in two ways.
Use the empty string value found in the Text toolbox drawer, under the Advanced menu. This is important because you will be adding to this string character by character.
Initialize the Variables
We are ready to start entering numbers. This is a table of the first fourteen binary numbers and their decimal equivalents.
Your goal is to use this table to figure out how to calculate a new correct decimal value based on whether a user enters a 0, or a 1 as the next number in the string. If the first number the human enter binar is a 1, you automatically know the new decimal value is a 1. If the second number that is entered is a 0, then your decimal value goes from 1 to 2.
However, if the second number is also a 1, then your new decimal value goes from 1 to 3.
At that point, you either have a 10, or a 11 in your binary string. The decimal value of binary 10 is 2. If the third number entered is a 0, then your new decimal value goes from 2 to 4. If the third number entered is a 1, then your new decimal value goes from 2 to 5.
Enter Binary Code:
If, on the other hand, you have 11 in your binary string, then your decimal value is 3. If the third number entered is a 0, then your new decimal value goes from 3 to 6. If the third number entered is a 1, then your new decimal value goes from 3 to 7.
See if you can spot a pattern that will help you figure out, for any given decimal value, what the new decimal value should be if the user enters a 0, or if the user enters a 1. Pseudocode Recall from our Algorithms lesson that it is a good idea to write out your algorithm in plain English, before you start coding in MakeCode.
This is called pseudocode. The Input for this program will be the buttons.
Try to write out what should happen when each of the buttons is pressed. Here is one possible solution.
Entering and viewing binary numbers
Show the current value of the binary string. Update the decimal value with the total.
Did ever wonder how they actually work to signal an input event? This is pretty straightforward if you have been keeping track of the decimal value every time someone presses a button. The pattern is as enter binar spoiler alert!
Whenever someone enters a 0, the new decimal value is twice the previous value. If someone enters a 1, the new decimal value is twice the previous value, plus 1. For Button A, you will need to use the enter binar Math block and your binary variable block to create the proper formula.
You will need to put that formula inside another Math addition block in order to add one to the result.
How to use the Binary Translator? Write or paste the binary code into the first field. Press the Translate button to get the binary code converted to text. Optionally, you can Copy the output to clipboard, or Save it as a file on your device. How to Convert Binary to Text ASCII There are several methods for learning binary to text conversion online, whether you want to learn yourself, or have an online binary converter do it for you.
Here is the completed program. Have someone else try your program out. Then think about binary options interesting facts the program might be improved.
Here are some additional modifications you might try: Add a way to clear the binary and decimal values so you can start over. Add a way to erase the previous value.