HW2: ==== PART I: THEORY ============== Answer all questions in part I. Submit your work on paper. Please remember to write down your name on your submissions and to staple all of your pages. 1. Convert the following decimal numbers to binary: 2, 7, 14, 31, 44, 79, 127, 157, 249, 255 2. Convert the following binary numbers to decimal: 1, 10, 11, 101, 1001, 1010, 10011, 11001, 11001100, 11101011 3. What is the largest number that you can represent with 8 bits? 16 bits? 24 bits? 32 bits? 4. What decimal number is represented by the following float numbers (single precision - 32 bits). You will need to refer to the IEEE-754 standard (see the following Wikipedia link http://en.wikipedia.org/wiki/IEEE_754 ) 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5. This is similar to #4 but uses double-precision (64 bits). You will need to refer to the IEEE-754 1985 standard (see the following Wikipedia link ( http://en.wikipedia.org/wiki/IEEE_754 ) 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6. Convert the following decimal numbers to float numbers (single precision - 32 bits) 1.0, -1.75, -2.75, 56.0, 64.0, 1024.0 7. Convert the following binary numbers to hexadecimal numbers. Hexadecimal numbers were not covered during the lectures but you can use google to find out information about them. 01, 0101, 1010, 1100, 1101, 111010, 1011001, 11010011, 1100001100101101, 0011011011011111 8. Covert the following hexadecimal numbers to binary numbers: 0xCAFE, 0xBABE, 0xFEED, 0xBAADF00D, 0xDEADBEEF 9. Convert the following decimal numbers to hexadecimal numbers: 3, 6, 9, 10, 12, 14, 16, 25, 31, 55 10. Convert the following hexadecimal numbers to decimal numbers: 0x1, 0x8, 0xA, 0xAB, 0xFF, 0xF1D, 0xA4D3, 0x0FFF PART II: PROGRAMS ================= Pick 5 of the following 8 programming projects. All problems have equal weight. Your grade will not be affected by the problems that you pick. 1. Write a C program that calculates the real roots of quadratic equations. Quadratic equations have the form a*x*x + b*x + c = 0. The program must prompt the user to enter the parameters a, b, and c. The program must then output x1 and x2. You can assume that the user will always enter parameters for which the equations has 2 roots. In other words, the program is not required to check if no real solutions exist. Sample outputs: For a=1, b=2, c=0 -> x1= -2, x2=0 For a=2, b=3, c=-5 -> x1= -2.5, x2=1 If you need to refresh your math knowledge see: http://en.wikipedia.org/wiki/Quadratic_equation 2. Write a C program that calculates your final numeric grade for this class. Your program must ask the user to enter five floating point values (in the range 0.00 to 100.00) which represent your scores for attendance, homework assignments (all 10 homeworks combined), first midterm exam, second midterm exam, and final exam. The weight of each of the five components is specified in the class syllabus. For example, suppose that the user enters (100.00, 90.00, 85.0, 90.0, and 92.0). In this case the program should print out 0.905 (which according to the syllabus will correspond to A-, but you don't have to print the letter grade). 3. Write a C program that prints the multiplication table for a single number. The program must ask the user to enter the number. Suppose that the user enters 5. The program must then output: 1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25 6 x 5 = 30 7 x 5 = 35 8 x 5 = 40 9 x 5 = 45 10 x 5 = 50 The program must format the output so that all numbers are right justified and the 'x'-s and '='-s form nice columns. 4. Exercise 4 from Section 2.5 (page 71) in the textbook. Submit your answers for a) ... r) in a textfile named Ex3.txt 5. Exercise 5 from Section 2.5 (page 72) in the textbook, but use the following variable values instead: color = 1, crayon = 1.7, red=4, straw=4, purple = 0.2e2; Submit your answers for a) ... f) in a textfile named Ex5.txt 6. Exercise 2 from Section 2.6 (page 75) in the textbook. Submit your answers in a textfile named Ex2.txt 7. Programming Project #8 on page 92 in the textbook. 8. Programming Project #13 on page 93 in the textbook. Part III: For advanced or bored students only!!! ======== Invent one programming question for Midterm 1. Submit the complete source code and a complete problem description (using C comments) at the top of your source file. The program must be solvable with the material covered in Chapters 1-3 in the textbook. If your question is good then you may get to solve your own program during the exam.