### CS170: Homework 1

This is the first homework for CS170 (Section 002). Unlike labs, you are expected to do homeworks on your own. Future homeworks will involve programming, but this first one is mostly written, and you should turn it in on paper.

Note this homework refers to some examples from Section 1 of our lecture notes.

Like all work for this class, the Emory Honor Code applies. You should do your own work on all problems, unless you are explicitly instructed otherwise. If you get stuck or have questions, ask your instructor or a TA for help.

• Question 1 (10 pts)

• How many bits (not bytes) are there in one mega byte (MB) of memory?

(Recall, for Computer Science `kilo' means a number that is a power of 2 that is close to 1000.)

• Question 2 (20 pts)

• Google decimal to binary conversion tool to find an online tool that let you convert decimal number into binary numbers, and vice versa.

Use this tool to find the binary number for the following decimal numbers:

• 254
• 255
• 256 (notice that you have 9 digits in the binary number !)
• 257
• 258

• Do the following steps:

• Convert the decimal number 556 into binary
• Remove all digit except for the last 8 digits (i.e., keep only the right-most 8 digits)
• Convert the resulting binary number into a decimal number.

What is the resulting decimal number ?

• Question 3 (10 pts)

• Letters in the English Alphabet is stored inside the computer as number

The encoding method used to represent the alphabet is known as the ASCII code (American Standard Code for Information Interchange).

• The ASCII-CODE.COM contains an ASCII code table.

Use the ASCII code table to find out what text is encoded by the following sequence of (decimal) byte codes?

 ``` 72 101 108 108 111 32 101 118 101 114 121 111 110 101 32 33 ```

• Question 4 (10 pts)

• Searching online, find the minimum and maximum integer value that can be represented by each of the following Java types:

 byte              short char int long

Also for each of these types, how many bits do we need to store such a value?

• Question 5 (20 pts)

• Compute the GCD of A=56 and B=91, using Euclid's algorithm as described in the lecture notes.

Trace out each step, like in the example with 28 and 36.

 ``` Initially: A = 56 B = 91 After 1 iteration: A = B = After 2 iterations: A = B = After 3 iterations: A = B = After 4 iterations: A = B = After 5 iterations: A = B = After 6 iterations: A = B = After 7 iterations: A = B = After 8 iterations: A = B = After 9 iterations: A = B = After 10 iterations: A = B = (use as many rows as needed) ```

• Question 6 (30 pts)

• Consider the following algorithm:

 ``` R = 47; Q = 0; D = 9; as long as R ≥ D do { R = R − D; Q = Q + 1; } ```

Trace out each step, like in the Euclid example: (20 pts)

 ``` Initially: R = 47 Q = 0 After 1 iteration: R = Q = After 2 iterations: R = Q = After 3 iterations: R = Q = After 4 iterations: R = Q = After 5 iterations: R = Q = After 6 iterations: R = Q = After 7 iterations: R = Q = (use as many rows as needed) ```

What does this algorithm accomplish ? (10 pts)

In other words:

• What value does the algorithm compute in the variable R ?
• What value does the algorithm compute in the variable Q ?

Hint: it has something to do with division.