Advertisement

Floating-point calculator

Convert decimal values to IEEE 754 binary32 or binary64 bit patterns and decode sign, exponent and fraction fields, including zeros, subnormals and infinities.

Calculator

Also accepts NaN, Infinity, -Infinity and -0.

Represented value
0.10000000149011612
Complete binary pattern
00111101110011001100110011001101
Hexadecimal pattern
3DCCCCCD
Sign bit
0.000000
Stored exponent
123.000000
Fraction field
10011001100110011001101
Classification
Normal
Rounding difference
1.4901161138336505e-9

Advertisement

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.

Sources

Advertisement