HomeDeveloper & IT › IEEE 754 Floating-Point Converter

IEEE 754 Floating-Point Converter

Encodes a decimal number as an IEEE 754 binary32 (single) or binary64 (double) value and reports the sign, exponent and mantissa bit fields, the hexadecimal and binary representation, the exact value actually stored and the rounding error.

When to use

You need the hex or binary encoding of a float, want to see why 0.1 is not exactly representable, or need to classify a value as normal, subnormal, zero or infinity.

Do not use when: You want integer bit patterns (use bitwise-operations or base-converter) or need decimal-to-binary conversion of integers only.

Formula

value = (−1)^sign × (1 + mantissa / 2^m) × 2^(biased_exponent − bias) for normal numbers; (−1)^sign × (mantissa / 2^m) × 2^(1 − bias) for subnormals; m = 23, bias = 127 (single) or m = 52, bias = 1023 (double)

Encoding uses a DataView (round-to-nearest-even as specified by IEEE 754-2019). Inputs are JavaScript doubles, so the double path never has a rounding error; the exact decimal is computed with integer arithmetic from the stored bits.

Inputs

ParameterTypeUnitRequiredDescription
valuenumberyesThe number to encode; parsed as a JavaScript double first, then rounded to single precision when precision = single.
precisionenum: single | doubledefault singleIEEE 754 format: 1+8+23 bits (single) or 1+11+52 bits (double).

Outputs

OutputTypeUnitDescription
sign_bitinteger0 for positive, 1 for negative.
exponent_bitsstringThe 8 (single) or 11 (double) biased exponent bits.
mantissa_bitsstringThe 23 or 52 fraction bits (the leading 1 of normal numbers is implicit).
biased_exponentintegerExponent field as an unsigned integer (bias 127 for single, 1023 for double).
unbiased_exponentintegerbiased_exponent − bias; subnormals and zero use 2^(1 − bias) instead.
significandnumber1.fraction for normal numbers (0.fraction for subnormals), so that value = (−1)^sign × significand × 2^exponent.
hexstringAll bits as a hex word, e.g. 0x3F800000.
binarystringAll 32 or 64 bits, sign first.
stored_valuenumberThe value actually representable in the chosen precision (rounded to nearest, ties to even).
stored_value_exactstringExact decimal expansion of the stored binary value.
rounding_errornumbervalue − stored_value (0 when the input is exactly representable).
classificationstringnormal, subnormal, zero, infinity or nan.

Example

1.0 in single precision: {"value":1,"precision":"single"}{"sign_bit":0,"biased_exponent":127,"unbiased_exponent":0,"hex":"0x3F800000","exponent_bits":"01111111","mantissa_bits":"00000000000000000000000","stored_value":1,"rounding_error":0,"classification":"normal"}

0.1 in single precision: {"value":0.1,"precision":"single"}{"hex":"0x3DCCCCCD","biased_exponent":123,"unbiased_exponent":-4,"stored_value":0.100000001490116,"stored_value_exact":"0.100000001490116119384765625","mantissa_bits":"10011001100110011001101","rounding_error":-1.4901161193847655e-9,"classification":"normal"}

GET https://tttkmbb.com/api/v1/calculate/ieee-754-float?value=1&precision=single

Machine access

Sources

FAQ

Why is 0.1 stored as 0.100000001490116?

0.1 has an infinite binary expansion (0.000110011…), so it is rounded to the nearest of the 2^23 fractions available at that exponent; the error of about 1.49 × 10⁻⁹ is the rounding_error output.

What is a subnormal number?

A value with exponent field 0 and a non-zero mantissa: it is scaled by 2^(1 − bias) without the implicit leading 1, filling the gap between zero and the smallest normal number (1.18 × 10⁻³⁸ for single).

Can I enter infinity or NaN?

Not directly (inputs must be finite), but values beyond 3.4 × 10³⁸ overflow to infinity in single precision and are classified as such.

Related calculators