In: Computer Science
write value of PI(3.14159) in IEEE-754 single-precision format
Converting 3.14159 to binary Convert decimal part first, then the fractional part > First convert 3 to binary Divide 3 successively by 2 until the quotient is 0 > 3/2 = 1, remainder is 1 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 11 So, 3 of decimal is 11 in binary > Now, Convert 0.14158999999999988 to binary > Multiply 0.14158999999999988 with 2. Since 0.28317999999999977 is < 1. then add 0 to result > Multiply 0.28317999999999977 with 2. Since 0.5663599999999995 is < 1. then add 0 to result > Multiply 0.5663599999999995 with 2. Since 1.132719999999999 is >= 1. then add 1 to result > Multiply 0.13271999999999906 with 2. Since 0.2654399999999981 is < 1. then add 0 to result > Multiply 0.2654399999999981 with 2. Since 0.5308799999999962 is < 1. then add 0 to result > Multiply 0.5308799999999962 with 2. Since 1.0617599999999925 is >= 1. then add 1 to result > Multiply 0.06175999999999249 with 2. Since 0.12351999999998498 is < 1. then add 0 to result > Multiply 0.12351999999998498 with 2. Since 0.24703999999996995 is < 1. then add 0 to result > Multiply 0.24703999999996995 with 2. Since 0.4940799999999399 is < 1. then add 0 to result > Multiply 0.4940799999999399 with 2. Since 0.9881599999998798 is < 1. then add 0 to result > Multiply 0.9881599999998798 with 2. Since 1.9763199999997596 is >= 1. then add 1 to result > Multiply 0.9763199999997596 with 2. Since 1.9526399999995192 is >= 1. then add 1 to result > Multiply 0.9526399999995192 with 2. Since 1.9052799999990384 is >= 1. then add 1 to result > Multiply 0.9052799999990384 with 2. Since 1.8105599999980768 is >= 1. then add 1 to result > Multiply 0.8105599999980768 with 2. Since 1.6211199999961536 is >= 1. then add 1 to result > Multiply 0.6211199999961536 with 2. Since 1.2422399999923073 is >= 1. then add 1 to result > Multiply 0.24223999999230728 with 2. Since 0.48447999998461455 is < 1. then add 0 to result > Multiply 0.48447999998461455 with 2. Since 0.9689599999692291 is < 1. then add 0 to result > Multiply 0.9689599999692291 with 2. Since 1.9379199999384582 is >= 1. then add 1 to result > Multiply 0.9379199999384582 with 2. Since 1.8758399998769164 is >= 1. then add 1 to result > Multiply 0.8758399998769164 with 2. Since 1.7516799997538328 is >= 1. then add 1 to result > Multiply 0.7516799997538328 with 2. Since 1.5033599995076656 is >= 1. then add 1 to result > Multiply 0.5033599995076656 with 2. Since 1.0067199990153313 is >= 1. then add 1 to result > Multiply 0.006719999015331268 with 2. Since 0.013439998030662537 is < 1. then add 0 to result > Multiply 0.013439998030662537 with 2. Since 0.026879996061325073 is < 1. then add 0 to result > Multiply 0.026879996061325073 with 2. Since 0.053759992122650146 is < 1. then add 0 to result > Multiply 0.053759992122650146 with 2. Since 0.10751998424530029 is < 1. then add 0 to result > Multiply 0.10751998424530029 with 2. Since 0.21503996849060059 is < 1. then add 0 to result > Multiply 0.21503996849060059 with 2. Since 0.43007993698120117 is < 1. then add 0 to result > Multiply 0.43007993698120117 with 2. Since 0.8601598739624023 is < 1. then add 0 to result > Multiply 0.8601598739624023 with 2. Since 1.7203197479248047 is >= 1. then add 1 to result > Multiply 0.7203197479248047 with 2. Since 1.4406394958496094 is >= 1. then add 1 to result > Multiply 0.4406394958496094 with 2. Since 0.8812789916992188 is < 1. then add 0 to result > Multiply 0.8812789916992188 with 2. Since 1.7625579833984375 is >= 1. then add 1 to result > Multiply 0.7625579833984375 with 2. Since 1.525115966796875 is >= 1. then add 1 to result > Multiply 0.525115966796875 with 2. Since 1.05023193359375 is >= 1. then add 1 to result > Multiply 0.05023193359375 with 2. Since 0.1004638671875 is < 1. then add 0 to result > Multiply 0.1004638671875 with 2. Since 0.200927734375 is < 1. then add 0 to result > Multiply 0.200927734375 with 2. Since 0.40185546875 is < 1. then add 0 to result > Multiply 0.40185546875 with 2. Since 0.8037109375 is < 1. then add 0 to result > Multiply 0.8037109375 with 2. Since 1.607421875 is >= 1. then add 1 to result > Multiply 0.607421875 with 2. Since 1.21484375 is >= 1. then add 1 to result > Multiply 0.21484375 with 2. Since 0.4296875 is < 1. then add 0 to result > Multiply 0.4296875 with 2. Since 0.859375 is < 1. then add 0 to result > Multiply 0.859375 with 2. Since 1.71875 is >= 1. then add 1 to result > Multiply 0.71875 with 2. Since 1.4375 is >= 1. then add 1 to result > Multiply 0.4375 with 2. Since 0.875 is < 1. then add 0 to result > Multiply 0.875 with 2. Since 1.75 is >= 1. then add 1 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.14158999999999988 of decimal is .00100100001111110011111000000011011100001100110111 in binary so, 3.14159 in binary is 11.00100100001111110011111000000011011100001100110111 3.14159 in simple binary => 11.00100100001111110011111000000011011100001100110111 so, 3.14159 in normal binary is 11.00100100001111110011111000000011011100001100110111 => 1.10010010000111111001111 * 2^1 single precision: -------------------- sign bit is 0(+ve) exp bits are (127+1=128) => 10000000 Divide 128 successively by 2 until the quotient is 0 > 128/2 = 64, remainder is 0 > 64/2 = 32, remainder is 0 > 32/2 = 16, remainder is 0 > 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 10000000 So, 128 of decimal is 10000000 in binary frac bits are 10010010000111111001111 so, 3.14159 in single-precision format is 0 10000000 10010010000111111001111 in hexadecimal it is 0x40490FCF