Question

When converting a number from base 10 to binary using the floating point bit model, what determines how many zeros you "zero pad" the fraction to the right of the radix?

Take for example -44.375 It was a question on a test in my systems programming course, and below is the answer the prof provided the class with... I posted this because most comments below seem to argue what my professor states in the answer and causing some confusion.

Answer: 1 1000 0100 0110 0011 0000 0000 0000 000 -- sign bit: 1 -- fixed point: -44.375 = 25 + 23 + 22 + 2-2 + 2-3

           = 101100.011

          = 1.01100011 * 2<sup>5</sup>

-- exponent: 5 + 127 = 132 = 1000 0100

-- fraction: 0110 0011 0000 0000 0000 000

Marking:

-- 1 mark for correct sign bit -- 2 marks for correct fixed point representation -- 2 marks for correct exponent (in binary) -- 2 marks for correct fraction (padded with zeros)

Was it helpful?

Solution 2

To determine the significand of an IEEE-754 32-bit binary floating-point value:

Figure out where the leading (most significant) 1 bit is. That is the starting point. Calculate 23 more bits. If there is anything left over, round it into last of the 24 bits (carrying as necessary).

Exception: If the leading bit is less than 2-126, use the 2-126 bit as the starting point, even though it is zero.

That gives the mathematical significand. To get the bits for the significand field, remove the first bit. (And, if the exception was used, set the encoded exponent to zero instead of the normal value.)

Another exception: If the leading bit, after rounding, is 2128 or greater, the conversion overflows. Set the result to infinity.

OTHER TIPS

Unless the float is very small, there is no left "zero pad" of the fraction.

The sample here is -1.63 (in hexadecimal) * power(2,5 (decimal)).
The exponent is adjusted until the leading digit is 1.

printf("%a\n", -44.375);
// -0x1.63p+5

[Edit]

Your prof wants to see "2 marks for correct fraction (padded with zeros)" as the number of bits in a float, so the significand in your example is

1.0110 0011 0000 0000 0000 000

The leading 1 is not stored explicitly in a typical float.

OP "what determines how many zeros you "zero pad" the fraction to the right of the radix?
A: IEEE 754 binary32 (a popular float implementation) has a 24 bit significand. A lead bit (usually 1) and a 23-bit fraction. Thus your "right" zero padding goes out to fill 23 places.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top