CS 61C, Summer 2010
Due Friday, June 25, 2010 @ 11:59pm
Last updated Wednesday, Jun. 23, 2010 @ 2:00pm
This assignment checks your understanding of the material in P&H Chapter 1 as well as some number representation basics. It will also give you practice compiling and executing C programs.
Submit your solution by creating a directory named hw1 that contains files named cod.txt and majorbit.c. (Note that capitalization matters in file names; the submission program will not accept your submission if your file names differ at all from those specified.) From within that directory, type "submit hw1". Partners are not allowed on this assignment.
$ mkdir ~/hw $ cp -r ~cs61c/hw/01/ ~/hwAll the files referred in this homework will be in the folder you copied.
In cod.txt, answer the following questions:
P&H (4th) problems 1.1.1-1.1.26 (these are very short questions), reproduced below:
Find the word or phrase from the list below that best matches the description in the following questions. Use the numbers to the left of the words in the answer. Each answer should be used only once.
1. virtual worlds | 14. operating system |
2. desktop computers | 15. compiler |
3. servers | 16. bit |
4. low-end servers | 17. instruction |
5. supercomputers | 18. assembly language |
6. terabyte | 19. machine language |
7. petabyte | 20. C |
8. datacenters | 21. assembler |
9. embedded computers | 22. high-level language |
10. multicore processors | 23. system software |
11. VHDL | 24. application software |
12. RAM | 25. cobol |
13. CPU | 26. fortran |
P&H (4th) problems 1.2.4:
Assuming that a cache memory is ten times faster than a DRAM memory, that DRAM is 100,000 times faster than magnetic disk, and that flash memory is 1000 times faster than disk, find how long it takes to read a file from a DRAM, a disk, and a flash memory if it takes 2 microseconds from the cache memory?
P&H (4th) problems 2.7.1, 2.7.2, 2.7.5:
The following problems explore number conversions from signed and unsigned binary number to decimal numbers.
a. | 0b 1010 1101 0001 0000 0000 0000 0000 0010 |
b. | 0b 1111 1111 1111 1111 1011 0011 0101 0011 |
2.7.1. For the patterns above, what base 10 number does it represent, assuming that it is a two's complement integer?
2.7.2. For the patterns above, what base 10 number does it represent, assuming that it is an unsigned integer?
a. | 2147483647 |
b. | 1000 |
2.7.5. For the base ten numbers above, convert to two's complement hexadecimal.
majorBit()
in majorbit.c
that returns the bit that appears the most in the binary representation of its unsigned integer argument. For example, for the number 5 (101 in binary), the function will return 1 since 1 appears 2 times whereas 0 only appear 1 time. Similarly, for the number 4 (100 in binary) the function will return 0. If there is a tie the program should return 2. Remember to fill in the identification information and run the completed program to verify correctness.
/* Name: Lab section time: */ #include <stdio.h> int majorBit (unsigned int n); int main ( ) { printf ("# majority bit in base 2 representation of %u = %d, should be 0\n", 0, majorBit (0)); printf ("# majority bit in base 2 representation of %u = %d, should be 1\n", 1, majorBit (1)); printf ("# majority bit in base 2 representation of %u = %d, should be 2\n", 2863311530u, majorBit (2863311530u)); printf ("# majority bit in base 2 representation of %u = %d, should be 0\n", 536870912, majorBit (536870912)); printf ("# majority bit in base 2 representation of %u = %d, should be 1\n", 4294967295u, majorBit (4294967295u)); return 0; } int majorBit (unsigned int n) { /* your code here */ }
# ./majorbit 17 0 # ./majorbit 255 1 # ./majorbit 10 20 too many arguments! # ./majorbit [the same result as from problem 5]You may assume that the single argument will always be an integer in the range from 0 to 2^31-1. You will find the function
atoi
helpful.
Extra for experts: Implement this exercise without using the library function atoi
(or something comparable).