How this calculator works
Binary32 stores one sign bit, eight exponent bits and 23 fraction bits; binary64 uses one, 11 and 52. Normal numbers have an implicit leading one. An all-zero exponent encodes zeros and subnormals; an all-one exponent encodes infinities and NaNs. Decimal input first enters JavaScript binary64, then binary32 mode rounds it once more. Very long decimals can therefore differ from a direct arbitrary-precision decimal-to-binary32 conversion.
Formula
Normal: (-1)^sign x (1 + fraction/2^f) x 2^(stored exponent - bias). Bias is 127 for binary32 and 1023 for binary64. Subnormals omit the leading one and use exponent 1-bias.
Worked example
Binary32 1 is 0 01111111 00000000000000000000000, hex 3F800000. Decimal 0.1 becomes binary32 0.10000000149011612, hex 3DCCCCCD.
Advertisement
Frequently asked questions
Why does 0.1 change?
One tenth has a repeating binary expansion. A fixed-width format stores a nearby representable value.
Are NaN payload bits preserved?
Decoding displays the supplied bits. Encoding the text NaN uses the runtime canonical representation rather than a user-selected payload.
Can the result show negative zero?
Yes. Its sign bit is one while exponent and fraction are zero. The text readout preserves -0.