Teacher's Choice

Binary Timer Snap! Project (Teacher's Choice)

In this project you will create a timer that reports the number of seconds elapsed in both decimal and binary notations.

  1. First, review this Binary Timer, and then discuss what you know about binary notation.
    binary timer Snap! project
  2. You can visit this wikihow.com page and discuss conversion from base 10 to base 2.

    Note that there are two methods presented in the link.

    • The first method (Short Division by Two with Remainder), though more general (i.e. it works for conversion to any base) is a bit harder to understand why it works.
    • The second method, (Descending Powers of Two and Subtraction) is easier to understand and is in tandem with the video you watched earlier.
    Choose one of the methods described and come up with a simple algorithm for this procedure.

  3. Examine the student file linked here with which you will be working. Several sprites, blocks, and costumes have already been created for you. The getBinaryDigits block (in Timer) is the only place where you will need to fill in some code.

If you look at the Timer sprite code, you will see that the timer block (from the "Sensing" menu) is used as a time keeper. The decimal and binary digits are computed and stored in lists, and then a broadcast is made to the sprites representing the digits to put on the appropriate costumes (0 and 1 for the binary digits and 0 through 9 for the decimal digits.)


Timer Code

The "warp" block is used to ensure that all the computation within the block is completed prior to the refreshing of the screen .

The code for extracting the base 10 digits of a given number,getDecimalDigits, is written for you. If you are using method 2 (Descending Powers of Two and Subtraction) to write getBinaryDigits you can ignore the code in getDecimalDigits. If you are using method 1 (Short Division by Two with Remainder) however, you can use this code as a model to write the getBinaryDigits code as it is based on method 1.

  1. Review and understand the code for the rest of the sprites representing the decimal digits. Check that your timer works in the decimal notation.
  2. Now write the code for the getBinaryDigits custom block using either conversion method. If you get stuck, you can get some hints here. When you are done, review the code for the sprites representing the 8 binary digits. Check that the timer works in the binary notation.
  1. Talk with Your Partner In this project, you generated the binary number representation of decimal numbers 0 through 255. While it takes only 3 digits to represent the number 255 in base 10, it requires 8 digits to represent the same number in base 2. Can you explain why?
  2. Create a Hexadecimal Timer Project in Snap!
 
You might want to make use of the current time block in the "Sensing" menu:
  1. Create a binary clock that shows the current time in base 2. For example:
    Hr : Min : Sec
    07 : 40 : 16
    0111 : 101000 : 010000
  2. Create a hexadecimal clock that shows current time in base 16. For example:
    Hr : Min : Sec
    12 : 40 : 59
    C : 28 : 3B
  3. Tough Stuff Create a Snap! program that converts any number in any given base to its equivalent in another given base. The dialog with the user may be something like this:
    • User inputs initial base: 10
    • User inputs number to convert: 29
    • User inputs final base: 3
    • Program outputs: 29 in base 10 is 1002 in base 3