CS 202 Fall 2010

Homework Assignment #4 : Due Friday 10/1 Before Lecture

The purpose of this assignment is learn about how data is stored inside a computer and how control flow works in Scratch with variables. The questions are all straight-forward and can be answered with pencil, paper, and possibly a calculator.

  1. Determine the decimal value of the following unsigned binary numbers:
    1. 1110
    2. 10110
    3. 11111
    4. 10000000
  2. Determine the decimal value of the following numbers in different bases:
    1. 110 (base 2)
    2. 110 (base 4)
    3. 110 (base 8, or octal)
    4. 110 (base 16, or hexadecimal)
    5. 2a9 (base 16)
  3. Using 8 bits, calculate the unsigned binary representation of each of the following decimal values:
    1. 10
    2. 27
    3. 31
    4. 511
  4. Using the ASCII code set, show the binary representation for the following character strings. Please terminate each string with a NULL character (i.e., 0000 0000); note that a NULL character is different than a blank space (i.e., 0010 0000). You can find the ASCII code on page 141 of the textbook (Figure 4.3) or from the slides from Lecture 8.
    1. hi!
    2. Bye
    3. $2.05
  5. This question asks about the behavior of scripts written in Scratch. You may implement these scripts in Scratch if you want to check your answers, but you should be able to answer the questions by just looking at the scripts and thinking about how they will run.
    1. You have a cat executing the following script. Draw a picture showing what the cat does over time. Be precise with the initial state and the timing of each action that changes his appearance in some way.

    2. For each of the following six scripts activated by "When Green Flag clicked", state whether or not it results in the same behavior as the original script above. If the script results in different behavior, describe the new behavior.

  6. Consider the following Script which has access to one variable called x. This script calculates a bizarre sequence of numbers called a Collatz sequence. Believe it or not, no one knows for sure if this script is guaranteed to terminate (or finish) for an arbitrary value of x! But, don’t worry, the script will definitely terminate quickly for all of the input values you need to consider.

    The block "x mod 2" divides x by 2 and returns the remainder. For example, "7 mod 2" returns 1 and "6 mod 2" returns 0.

    Imagine the program is run three different times, each with a different input value for x. For each run, show the value of x over time as the script runs; that is, show the new value of x at the end of each iteration of the repeat loop.

    1. Input x = 2
    2. Input x = 8
    3. Input x = 5

Menu

Fall 2010
Time: MWF 9:55-10:45
Room: 105 Psychology
Lab: 1370 CS (1st floor)


Instructor:
Prof Andrea Arpaci-Dusseau
Office Hours Tue 2:30-3:30, Wed 11-12
Office: 7375 Computer Sciences
Email: dusseau "at" cs.wisc.edu

  • CS202 Home
  • TAs and Lab Hours
  • Lecture Schedule w/ Slides
  • Grading
  • Homeworks
  • Projects
  • Exams
  • Scratch Examples
  • Readings
  • Computing Resources
  • Outreach Opportunity

  • Interesting Links
  • Scratch
  • UW Computer Sciences Dept