Exam 1, Version 2 (day listed as "Thur."). Solutions CS 213 Fall 2008 ********* Problem 1 ******** Expression Decimal Binary ----------------------------------- --- | 41 | 0010 1001 --- | -17 | 1110 1111 TMax | 127 | 0111 1111 TMax-TMin | -1 | 1111 1111 ux | 192 | 1100 0000 sa | -6 | 1010 b | -12 | 1111 0100 sc | 4 | 0100 ----------------------------------- ********* Problem 2 ******** A. True. It yields i when i < 0, and ~i when i >= 0 B. False. For 0 and TMin C. False. Converting i to floating point can cause rounding. E.g., for TMax D. False. For large values of i, e.g., TMax, the addition can overflow E. True. Will use floating point arithmetic, which does not overflow ********* Problem 3 ******** 111 00000 | +Inf | 10101 010 | 80 100 11000 | 7/2 | 10000 110 | 7/2 000 00001 | 1/128 | 01000 000 | 1/128 110 00000 | 8 | 10010 000 | 8 ********* Problem 4 ******** Blanks should be filled in as: long ** i < n j <= i M[i][j] < 0 i 0 ********* Problem 5 ******** H = 14 J = 48 ********* Problem 6 ******** A B D C ********* Problem 7 ******** long test(long a, long b, long c) { long answer = 8; switch(a) { case 5: c = b ^ 14; /* Fall through */ case 7: (or 0) case 0: (or 7) answer = c + 128; break; case 2: (or 4) answer = (c - b) << 3; (or 10) break; case 4: (or 2) answer = 10; (or (c - b) << 3) break; default: answer = 8; } return answer; } ********* Problem 8 ******** A. Allocate bytes as: aaaabbbbcxxxdddd exxxxxxxffffffff ggxxhhhh B. Answers vary. Here is one solution: ffffffffaaaabbbb ddddhhhhbbcexxxx C. 12 D. 4