In: Computer Science
Convert the following decimal numbers into their 32-bit floating point representation (IEEE single precision). You may use a calculator to do the required multiplications, but you must show your work, not just the solution.
1. -59.75 (ANSW: 11000010011011110000000000000000)
2. 0.3 (ANSW: 00111110100110011001100110011010 (rounded)
00111110100110011001100110011001 (truncated; either answer is
fine))
Please show all work
1) Converting 59.75 to binary Convert decimal part first, then the fractional part > First convert 59 to binary Divide 59 successively by 2 until the quotient is 0 > 59/2 = 29, remainder is 1 > 29/2 = 14, remainder is 1 > 14/2 = 7, remainder is 0 > 7/2 = 3, remainder is 1 > 3/2 = 1, remainder is 1 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 111011 So, 59 of decimal is 111011 in binary > Now, Convert 0.75 to binary > Multiply 0.75 with 2. Since 1.5 is >= 1. then add 1 to result > Multiply 0.5 with 2. Since 1.0 is >= 1. then add 1 to result > This is equal to 1, so, stop calculating 0.75 of decimal is .11 in binary so, 59.75 in binary is 111011.11 -59.75 in simple binary => 111011.11 so, -59.75 in normal binary is 111011.11 => 1.1101111 * 2^5 single precision: -------------------- sign bit is 1(-ve) exp bits are (127+5=132) => 10000100 Divide 132 successively by 2 until the quotient is 0 > 132/2 = 66, remainder is 0 > 66/2 = 33, remainder is 0 > 33/2 = 16, remainder is 1 > 16/2 = 8, remainder is 0 > 8/2 = 4, remainder is 0 > 4/2 = 2, remainder is 0 > 2/2 = 1, remainder is 0 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 10000100 So, 132 of decimal is 10000100 in binary frac bits are 11011110000000000000000 so, -59.75 in single-precision format is 1 10000100 11011110000000000000000 in hexadecimal it is 0xC26F0000 2) Converting 0.3 to binary Convert decimal part first, then the fractional part > First convert 0 to binary Divide 0 successively by 2 until the quotient is 0 Read remainders from the bottom to top as So, 0 of decimal is in binary > Now, Convert 0.3 to binary > Multiply 0.3 with 2. Since 0.6 is < 1. then add 0 to result > Multiply 0.6 with 2. Since 1.2 is >= 1. then add 1 to result > Multiply 0.19999999999999996 with 2. Since 0.3999999999999999 is < 1. then add 0 to result > Multiply 0.3999999999999999 with 2. Since 0.7999999999999998 is < 1. then add 0 to result > Multiply 0.7999999999999998 with 2. Since 1.5999999999999996 is >= 1. then add 1 to result > Multiply 0.5999999999999996 with 2. Since 1.1999999999999993 is >= 1. then add 1 to result > Multiply 0.1999999999999993 with 2. Since 0.3999999999999986 is < 1. then add 0 to result > Multiply 0.3999999999999986 with 2. Since 0.7999999999999972 is < 1. then add 0 to result > Multiply 0.7999999999999972 with 2. Since 1.5999999999999943 is >= 1. then add 1 to result > Multiply 0.5999999999999943 with 2. Since 1.1999999999999886 is >= 1. then add 1 to result > Multiply 0.19999999999998863 with 2. Since 0.39999999999997726 is < 1. then add 0 to result > Multiply 0.39999999999997726 with 2. Since 0.7999999999999545 is < 1. then add 0 to result > Multiply 0.7999999999999545 with 2. Since 1.599999999999909 is >= 1. then add 1 to result > Multiply 0.599999999999909 with 2. Since 1.199999999999818 is >= 1. then add 1 to result > Multiply 0.1999999999998181 with 2. Since 0.3999999999996362 is < 1. then add 0 to result > Multiply 0.3999999999996362 with 2. Since 0.7999999999992724 is < 1. then add 0 to result > Multiply 0.7999999999992724 with 2. Since 1.5999999999985448 is >= 1. then add 1 to result > Multiply 0.5999999999985448 with 2. Since 1.1999999999970896 is >= 1. then add 1 to result > Multiply 0.19999999999708962 with 2. Since 0.39999999999417923 is < 1. then add 0 to result > Multiply 0.39999999999417923 with 2. Since 0.7999999999883585 is < 1. then add 0 to result > Multiply 0.7999999999883585 with 2. Since 1.599999999976717 is >= 1. then add 1 to result > Multiply 0.5999999999767169 with 2. Since 1.1999999999534339 is >= 1. then add 1 to result > Multiply 0.19999999995343387 with 2. Since 0.39999999990686774 is < 1. then add 0 to result > Multiply 0.39999999990686774 with 2. Since 0.7999999998137355 is < 1. then add 0 to result > Multiply 0.7999999998137355 with 2. Since 1.599999999627471 is >= 1. then add 1 to result > Multiply 0.599999999627471 with 2. Since 1.199999999254942 is >= 1. then add 1 to result > Multiply 0.19999999925494194 with 2. Since 0.3999999985098839 is < 1. then add 0 to result > Multiply 0.3999999985098839 with 2. Since 0.7999999970197678 is < 1. then add 0 to result > Multiply 0.7999999970197678 with 2. Since 1.5999999940395355 is >= 1. then add 1 to result > Multiply 0.5999999940395355 with 2. Since 1.199999988079071 is >= 1. then add 1 to result > Multiply 0.19999998807907104 with 2. Since 0.3999999761581421 is < 1. then add 0 to result > Multiply 0.3999999761581421 with 2. Since 0.7999999523162842 is < 1. then add 0 to result > Multiply 0.7999999523162842 with 2. Since 1.5999999046325684 is >= 1. then add 1 to result > Multiply 0.5999999046325684 with 2. Since 1.1999998092651367 is >= 1. then add 1 to result > Multiply 0.19999980926513672 with 2. Since 0.39999961853027344 is < 1. then add 0 to result > Multiply 0.39999961853027344 with 2. Since 0.7999992370605469 is < 1. then add 0 to result > Multiply 0.7999992370605469 with 2. Since 1.5999984741210938 is >= 1. then add 1 to result > Multiply 0.5999984741210938 with 2. Since 1.1999969482421875 is >= 1. then add 1 to result > Multiply 0.1999969482421875 with 2. Since 0.399993896484375 is < 1. then add 0 to result > Multiply 0.399993896484375 with 2. Since 0.79998779296875 is < 1. then add 0 to result > Multiply 0.79998779296875 with 2. Since 1.5999755859375 is >= 1. then add 1 to result > Multiply 0.5999755859375 with 2. Since 1.199951171875 is >= 1. then add 1 to result > Multiply 0.199951171875 with 2. Since 0.39990234375 is < 1. then add 0 to result > Multiply 0.39990234375 with 2. Since 0.7998046875 is < 1. then add 0 to result > Multiply 0.7998046875 with 2. Since 1.599609375 is >= 1. then add 1 to result > Multiply 0.599609375 with 2. Since 1.19921875 is >= 1. then add 1 to result > Multiply 0.19921875 with 2. Since 0.3984375 is < 1. then add 0 to result > Multiply 0.3984375 with 2. Since 0.796875 is < 1. then add 0 to result > Multiply 0.796875 with 2. Since 1.59375 is >= 1. then add 1 to result > Multiply 0.59375 with 2. Since 1.1875 is >= 1. then add 1 to result > Multiply 0.1875 with 2. Since 0.375 is < 1. then add 0 to result > Multiply 0.375 with 2. Since 0.75 is < 1. then add 0 to result > Multiply 0.75 with 2. Since 1.5 is >= 1. then add 1 to result > Multiply 0.5 with 2. Since 1.0 is >= 1. then add 1 to result > This is equal to 1, so, stop calculating 0.3 of decimal is .010011001100110011001100110011001100110011001100110011 in binary so, 0.3 in binary is .010011001100110011001100110011001100110011001100110011 0.3 in simple binary => .010011001100110011001100110011001100110011001100110011 so, 0.3 in normal binary is .010011001100110011001100110011001100110011001100110011 => 1.00110011001100110011001 * 2^-2 single precision: -------------------- sign bit is 0(+ve) exp bits are (127-2=125) => 01111101 Divide 125 successively by 2 until the quotient is 0 > 125/2 = 62, remainder is 1 > 62/2 = 31, remainder is 0 > 31/2 = 15, remainder is 1 > 15/2 = 7, remainder is 1 > 7/2 = 3, remainder is 1 > 3/2 = 1, remainder is 1 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 1111101 So, 125 of decimal is 1111101 in binary frac bits are 00110011001100110011001 so, 0.3 in single-precision format is 0 01111101 00110011001100110011001 in hexadecimal it is 0x3E999999