15-213 Fall 2007 Midterm Exam Solutions There were two versions of the exam: version A and version B. You can tell the difference as follows: on question 5, if "status_array" (the last line of C code) was declared with 10 elements, then you had version A; if it was declared with 20 elements, then you had version B. ===================================================================== Solutions to Midterm Exam Version A ===================================================================== ********* Problem 1 ********* ((~(ux>>31)) & ux) != ux | False (MSB=0) x >= 0 ) => ((x ^ (x>>31))) <= 0 | False (x>0) ((-(!x)) & x) == 0 | True x < 0 => ((~x)+1) > 0 | False (TMin) x > 0 => (x+ux) > 0U | True x < 0 => (x-1) < 0 | False (TMin) x >= 0 => -(((~x) >> 1) + 1) > 0 | False (0, 1, TMax) ((~(x>>31))+1) == (x<0) | True ********* Problem 2 ********* Value: Sign Bit: Exponent: Significand: -1/1024 1 0000 0001 248 0 1110 1111 1 1001 0100 1 0010 1000 0 0101 1001 0 1000 0111 ********* Problem 3 ********* array[0] != 1 0 1 < n i++ array[i] != (array[i-1]*2) 0 1 ********* Problem 4 ********* 7x 3y 3 7 ********* Problem 5 ********* 12, 0 16, 4 160, 70 ********* Problem 6 ********* CT CT CT CI CI CO CO CO b, 2 hits ********* Problem 7 ********* ABCBEDE ABCEBDE ===================================================================== Solutions to Midterm Exam Version B ===================================================================== ********* Problem 1 ********* x > 0 => (x+ux) > 0U | True x >= 0 => -(((~x) >> 1) + 1) > 0 | False (0, 1, TMax) ((~(ux>>31)) & ux) != ux | False (MSB=0) ((-(!x)) & x) == 0 | True x < 0 => ((~x)+1) > 0 | False (TMin) x < 0 => (x-1) < 0 | False (TMin) ((~(x>>31))+1) == (x<0) | True x >= 0 => ((x ^ (x>>31))) <= 0 | False (x>0) ********* Problem 2 ********* Value: Sign Bit: Exponent: Significand: -1/1024 1 0000 0001 248 0 1110 1111 1 1001 0100 1 0010 1000 0 0101 1001 0 1000 0111 ********* Problem 3 ********* array[0] != 1 0 1 < n i++ array[i] != (array[i-1]*2) 0 1 ********* Problem 4 ********* 31x 3y 3 31 ********* Problem 5 ********* 16, 4 12, 0 320, 140 ********* Problem 6 ********* CT CT CT CI CI CO CO CO g, 2 hits ********* Problem 7 ********* ABCBEDE ABCEBDE