Exam 1 Solutions CS 213 Fall 2005 ********* Problem 1 ********* Expression | Decimal | Binary ----------------------------------- -- | -2 | 111 1110 -- | 19 | 001 0011 x | -16 | 111 0000 uy | 112 | 111 0000 x - uy | 0 | 000 0000 C promotes signed x to unsigned TMax+1 | -64 | 100 0000 TMin-1 | 63 | 011 1111 -TMin | -64 | 100 0000 TMin+TMin | 0 | 000 0000 TMax+TMin | -1 | 111 1111 ----------------------------------- ********* Problem 2 ********* ------------------------------------------------------------------- Format A Format B bits Value Bits Value Comment ------------------------------------------------------------------- 101 1110 15/2 1001 111 15/2 010 1001 25/32 0110 101 13/16 Round Up 110 1111 31/2 1011 000 16 Round Up 000 0001 1/64 0001 000 1/64 Denorm-->Norm ------------------------------------------------------------------- ********* Problem 3 ********* A 40-byte string results in the low order byte of the return address being overwritten with a '\0' byte, which changes the return address from 0x400f7c to 0x400f00, coincidently, the address of smoke(). ********* Problem 4 ********* L = 9 M = 33 N = 2 ********* Problem 5 ********* 0x400690: 0x00000000004004d1 0x00000000004004b8 0x4006a0: 0x00000000004004bb 0x00000000004004c0 0x4006b0: 0x00000000004004d4 0x00000000004004c3 ********* Problem 6 ********* int bar2(int x) { int y = 0; int z = x/4; for( ; z > 0 ; y++) z = z/4; return y; } } ********* Problem 7 ********* apr jan feb mar ********* Problem 8 ********* A. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |id| X|code | amount | name |X X X X X | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | data |in| X X X X X X X| +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | next | address |X X X +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ B. size(Union_1) = 48 bytes C. (a) Output #1 is u->value = 0x6c6c6548 (b) Output #2 is u->buf = Hello WoSM (c) Output #3 is u->buf = He