November 15, 1995 cs330 - Discrete Structures =========================== Fall 1995 Hw #4 - Solutions ================= In the following, bits have been sometimes grouped only for the sake of readability. 1 = a) 2^31 + 2^27 + 2^26 + 2^25 + 2^24 + 2^15 + 2^11 + 2^0 = 2,399,176,705 Or you can use hexadecimal for the conversion to get the same result. 8*16^7 + 15*16^6 + 8*16^3 + 8*16^2 b) same result c) complement 0111 0000 1111 1111 0111 0111 1111 1110 add one 1 --------------------------------------- 0111 0000 1111 1111 0111 0111 1111 1111 to get the absolute value of the number 7*16^7 + 15*16^5 + 15*16^4 + 7*16^3 + 7*16^2 + 15*16^1 + 15*16^0 = = 1895790591 The string 1000 1111 0000 0000 1000 1000 0000 0001, in 2's complement representation is the decimal -1895790591 d) sign: 1 -> negative number exp: 0001 1110 + 127 = 30 + 127 = -97 significand: 1.000 0000 1000 1000 0000 0001 ^ |-- the hidden bit The number is -1.00000001000100000000001*(2^-97) = = -(1 + (2^-8) + (2^-12) + (2^-23))*(2^-97) = -6.3370806*(10^-30) = = -6.3370806e-30 2 = a) 7*16^7 + 15*16^3 + 15*16^2 = 1879113472 b) 1879113472 c) because the MSB bit (the sign bit) is zero the number is positive and there is no need to take the number's 2's complement. +1879113472 d) sign: 0 -> positive number exp: 1110 0000 - 127 = 97 significand: 1.000 0000 1111 1111 0000 0000 = = 1.000 0000 1111 1111 The number is +1.000000011111111*(2^97) = = +1000000011111111*(2^97)*(2*-15) (moved the point to right) = +33023*2^82 = = 159689429364535596945288200192 = +1.5968942936*(10^29) (approximative value) 3 = a) binary: 11 1111 1111 (10 bits) octal: 1 111 111 111 -> 1777 (or 01777 to indicate it's octal) hexa: 3ff (or 0x3ff to indicate it's hexadecimal) b) can't represent using only 8 bits c) binary: 0000 0011 1111 1111 octal: 0 000 001 111 111 111 -> 001777 hexa: 0x03ff 4 = a) can't represent negative numbers using standard binary b) can't represent with 8 bits c) convert the absolute value (+1995) to standard binary 1995 -> 11111001011 pad with zero to the left to get a 16 bit representation of the absolute value 0000 0111 1100 1011 take the 2's comp representation of the absolute value to get the representation of -1995 complement: 1111 1000 0011 0100 add one: 1 ------------------- 1111 1000 0011 0101 (-1995 in 2's comp representation) octal: 1 111 100 000 110 101 -> 174065 (0174065) hexa: f835 (0xf835) 5 = a) 10.25 -> 1010.01 b) 1010.01 -> 1.01001*2^3 6 = 1.0 -> 1.0 -> 1.0*2^0 ^ ^ decimal binary Positive number: sign=0 (bit31) exp: 0 + 127 = 127 -> 0111 1111 (bits 30 to 23) ^ the bias significant: 000 0000 0000 0000 0000 0000 (bits 22 to 0) remember we don't represent the 1 left to the binary point. So the representation is 0 01111111 00000000000000000000000 ^ ^ ^ sign exp significand 7 = 0.1 -> 0.0(0011) in binary. We must make sure we'll keep enough fractional bits for the representation. The parantheses indicate the periodic fraction. Normalize 0.0(0011) -> 1.(1001)*(2^-4) sign: 0 exp: -4+127 = 123 -> 0111 1011 significand: 100 1100 1100 1100 1100 1100 So the representation is 0 01111011 10011001100110011001100 (0x3dcccccc) Note: In reality the representation is 0x3dcccccd (the LSB is 1) because of the way the standard deals with the LSB. But this has not been discussed in class. 8 = 0x1001154f357428 9 = Probably most SSNs can't be represented using 16 bits.