In: Computer Science
Represent the following decimal numbers using IEEE-754 floating point representation.
A. -0.375
B. -Infinity
C. 17
D. 5.25
a) -0.375 -0.375 Converting 0.375 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.37500000 to binary > Multiply 0.37500000 with 2. Since 0.75000000 is < 1. then add 0 to result > Multiply 0.75000000 with 2. Since 1.50000000 is >= 1. then add 1 to result > Multiply 0.50000000 with 2. Since 1.00000000 is >= 1. then add 1 to result > This is equal to 1, so, stop calculating 0.375 of decimal is .011 in binary so, 0.375 in binary is 00000000.011 -0.375 in simple binary => .011 so, -0.375 in normal binary is .011 => 1.1 * 2^-2 single precision: -------------------- sign bit is 1(-ve) exponent 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/significant bits are 10000000000000000000000 so, -0.375 in single-precision format is 1 01111101 10000000000000000000000 in hexadecimal it is 0xBEC00000 Answer: 1 01111101 10000000000000000000000 b) -Infinity Sign bit = 1 exponent bits = 11111111 mantissa bits = 00000000000000000000000 Answer: 1 11111111 00000000000000000000000 c) 17 17 Converting 17.0 to binary Convert decimal part first, then the fractional part > First convert 17 to binary Divide 17 successively by 2 until the quotient is 0 > 17/2 = 8, remainder is 1 > 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 10001 So, 17 of decimal is 10001 in binary > Now, Convert 0.00000000 to binary > Multiply 0.00000000 with 2. Since 0.00000000 is < 1. then add 0 to result > This is equal to 1, so, stop calculating 0.0 of decimal is .0 in binary so, 17.0 in binary is 00010001.0 17.0 in simple binary => 10001.0 so, 17.0 in normal binary is 10001.0 => 1.0001 * 2^4 single precision: -------------------- sign bit is 0(+ve) exponent bits are (127+4=131) => 10000011 Divide 131 successively by 2 until the quotient is 0 > 131/2 = 65, remainder is 1 > 65/2 = 32, remainder is 1 > 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 10000011 So, 131 of decimal is 10000011 in binary frac/significant bits are 00010000000000000000000 so, 17.0 in single-precision format is 0 10000011 00010000000000000000000 in hexadecimal it is 0x41880000 Answer: 0 10000011 00010000000000000000000 d) 5.25 5.25 Converting 5.25 to binary Convert decimal part first, then the fractional part > First convert 5 to binary Divide 5 successively by 2 until the quotient is 0 > 5/2 = 2, remainder is 1 > 2/2 = 1, remainder is 0 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 101 So, 5 of decimal is 101 in binary > Now, Convert 0.25000000 to binary > Multiply 0.25000000 with 2. Since 0.50000000 is < 1. then add 0 to result > Multiply 0.50000000 with 2. Since 1.00000000 is >= 1. then add 1 to result > This is equal to 1, so, stop calculating 0.25 of decimal is .01 in binary so, 5.25 in binary is 00000101.01 5.25 in simple binary => 101.01 so, 5.25 in normal binary is 101.01 => 1.0101 * 2^2 single precision: -------------------- sign bit is 0(+ve) exponent bits are (127+2=129) => 10000001 Divide 129 successively by 2 until the quotient is 0 > 129/2 = 64, remainder is 1 > 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 10000001 So, 129 of decimal is 10000001 in binary frac/significant bits are 01010000000000000000000 so, 5.25 in single-precision format is 0 10000001 01010000000000000000000 in hexadecimal it is 0x40A80000 Answer: 0 10000001 01010000000000000000000