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.
- Determine the decimal value of the following unsigned binary
numbers:
- 1110
- 10110
- 11111
- 10000000
- Determine the decimal value of the following numbers in different
bases:
- 110 (base 2)
- 110 (base 4)
- 110 (base 8, or octal)
- 110 (base 16, or hexadecimal)
- 2a9 (base 16)
- Using 8 bits, calculate the unsigned binary representation of each
of the following decimal values:
- 10
- 27
- 31
- 511
- 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.
- hi!
- Bye
- $2.05
- 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.
- 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.
- 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.
- 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.
- 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.
- Input x = 2
- Input x = 8
- Input x = 5
Menu
Fall 2010Time: 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