Homework 2 CS 61 Fall 2005 Prof. Frank Vahid See course web page for due date. 5% extra credit if working in study group of 3 or more -- see below. SHOW WORK, not just answers, for every problem, to receive credit. Turn in your work electronically as a plain text file (e.g., not a Word doc) with the file named cs61_hw2_firstname_lastname.txt. Exercise numbers (e.g., 2.4) refer to exercises in the Patt/Pattel textbook. 1. (Encodings) There are ten University of California campuses. (a) If every campus is assigned a unique bit pattern, what is the minimum number of bits required? (b) List the names of all ten campuses, and using the minimum number of bits, give each a unique bit encoding. 2. (Ranges of binary numbers) (a) Exercise 2.4 (a question on range of binary number) (b) Exercise 2.8(c) (a question on range of two's complement number) 3. (Using AND/OR/NOT logic) (a) Exercises 2.30(a), 2.30(c), 2.30(e) (questions on AND) (b) Exercise 2.34(a), 2.34(c) (questions on AND, OR, and NOT) (c) Exercise 2.53 (question using a truth table) 4. (Hexadecimal numbers) (a) Convert the following binary numbers to 2-digit hex numbers: 11110000 10100101 (b) Convert the following decimal numbers to 2-digit hexadecimal numbers, by first converting to binary, and then to hex: 23 42 5. ("Real" problems based on the above ideas) Say you are hired to write a program that controls a laser used during laser surgery. The laser can be positioned from left to right by setting an output S to any of -20, -19, ..., -1, 0, 1, ..., 19, 20. -20 represents the further left the laser can point, 0 is the middle, and 20 is the furthest right. (a) How many possible positions exist in the above range? (b) What is the minimum number of bits required to represent all those possible positions, using two's complement binary? Justify your answer! (c) The computer you'll be using represents numbers as 8-bit two's complement. You want to write a program that starts by moving the laser all the way left, then all the way right, and then rests the laser in the center. So your program has some instructions like this: POSITION -20 POSITION 20 POSITION 0 Show how the computer would represent those three numbers of your program using 8-bit two's complement representation. (d) The laser machine has eight "too-hot" sensors whose outputs automatically get read into an 8-bit variable S, with each bit in S representing the output of one sensor. Each sensor outputs 1 if the patient's skin is above a threshold temperature, 0 otherwise. So if all the sensors indicated too-hot, S=11111111. If only the rightmost sensor indicated too-hot, S=00000001. You want to write a program that sets an output R to 1 if any of the right four sensors indicate too-hot. Likewise, you want to set an output L to 1 if any of the four left sensors indicate too-hot. So you write a program something like this: T = S AND 00001111 if T is not equal to 00000000, then R=1, else R=0 U = S AND 11110000 if U is not equal to 00000000, then L=1, else L=0 (i) Show the results for T and U, if S=01010101. (ii) Rewrite the above program by replacing the four 8-bit binary numbers by 2-digit hex numbers. To indicate that a number is in hex, precede it by x, like this: xFF. 6. (Transistors) Exercise 3.4 (refer to top p, bottom p, left n, right n in your answers, since you are submitting text only and not drawings) 7. (Muxes/decoders) (a) Exercise 3.13 (b) Exercise 3.14 8. (Adders) Exercise 3.15 9. If you worked in a study group of 3 or more people, list names of study group partners, and date/time/place of meeting. Submissions should each be unique, but explaining concepts, answering each others' questions, and comparing answers for correctness is encouraged. ### end ###