Scratch: Barcodes and Binary!

advertisement
Scratch: Barcodes and Binary!
We are going to take our activity from the other day and turn it into a couple of Scratch
programs to practice the ideas we were learning! Each task will be a separate homework
problem.
Task 1: Write a Scratch program that will ask a user to type in 11 digits bar code and output the
proper checksum value for the 12th digit (refer to your Barcode packet if you forgot the
formula). You will either want to make a bunch of variables, or you can use the list feature to
keep track of all the digits.
Task 2: Write another Scratch program that will convert a single number into its barcode
counterpart, the user will enter if it is on the left or right-hand side and then the digit whose
bar pattern you want. Remember that all barcode digits are a pattern of 7 bars (white or black).
I would suggest doing this in two parts: First come up with a way to select the proper digit and
side (this will be a series of if statements), then come up with a way to draw the proper pattern
(you could do this with a bunch of different costumes on one or two sprites). Also you might
want to make it sort of small…you’ll have to do the whole bar code later!
Task 3: Take your code from Task 2 and use it to make a program that will draw an entire bar
code that the user types in. It will be easier if you ask the user to enter the digits one by one. A
couple of tips: Reuse the code from above, but add in some code that puts the sprite in the
correct place (remember there are 12 numbers!). Also remember that the first 6 digits will use
the left hand code and the second 6 will use the right hand code. You could also combine this
with Task 1 and check the number!
Task 4: Write a program that will take in a binary number and print out the decimal version of
the number. This program will benefit from the string separator program (linked above).
Remember that binary digits are actually reflecting powers of 2 (even 20 = 1) and they are read
from right to left. You will want to keep track of how many binary digits there are (you can use
the list length feature to help you with this) and then you’ll have a loop that will find the power
of two and add it to a total!
Task 5 (bonus): Write a Scratch program that will convert any number up to 1 million into
binary digits. Use what you learned above to help you out; you’ll have to do some checks to
see if your answer adds up!
Download