To convert a decimal number to IEEE floating-point representation:
- Find binary representation of the decimal number.
- Multiply by so that we now have (just like scientific notation, except the base is 2).
- Try to put number in the form
1.m
(m = mantissa; base-2 scientific notation) by increasing or decreasing the exponent field and moving the decimal (binary?) point accordingly. - The floating-point exponent field is the current exponent (on ) but plus 127. We need to do this since in IEEE representation, 2 is raised to the power of .
- Zero-pad the mantissa on the right if its length is fewer than 23 bits.
- Set the sign bit to 1 if original number is negative.
- Concatenate sign, exponent, and mantissa bits to get your floating-point representation of the decimal number.