Skip to content
KmapGen

IEEE 754 Converter

Convert decimal numbers to IEEE 754 floating point and back, in 16-bit half, bfloat16, 32-bit single and 64-bit double precision. Flip any bit, see the exact value that is stored and the rounding error.

Try:

Decimal input accepts -1.5e-3, fractions like 1/3, C hex floats like 0x1.8p3, pi, inf and nan. Conversion is exact: no intermediate rounding through a double.

Bits (click to flip)

sign · exponent · fraction · bit 31 on the left

Value stored (exact)0.100000001490116119384765625
Shortest round-trip decimal0.1
Rounding error (stored − input)0.000000001490116119384765625
≈ 1.49012e-9, relative 1.49e-8
Hexadecimal0x3DCCCCCD
Binary0 01111011 10011001100110011001101
Sign0 (positive)
Exponentfield 01111011 = 123; bias 127; actual exponent -4
Fraction (mantissa)10011001100110011001101 = 5033165 / 223 (hidden leading 1 added)
Formula(+1) × 1.60000002384185791015625 × 2123 − 127 = (+1) × 1.60000002384185791015625 × 2-4
CategoryNormal number
Gap to next value (ULP)2-27 ≈ 7.45058e-9
Next value up / down0.10000001 (0x3DCCCCCE)
0.099999994 (0x3DCCCCCC)

Decimal → IEEE 754, step by step

  1. Sign. The number is positive, so the sign bit is 0.
  2. Convert |x| to binary. 0.1 = 0.000112 (the overlined block repeats forever).
  3. Normalize. Move the binary point so one 1 is left of it: |x| = 1.… × 2-4.
  4. Exponent. Add the bias: -4 + 127 = 123 = 011110112.
  5. Fraction. Keep the 23 bits after the leading 1. The bits beyond them are not all zero, so the value is rounded to the nearest representable number (ties go to the even one). Fraction = 10011001100110011001101.
  6. Assemble sign | exponent | fraction: 0 01111011 10011001100110011001101 = 0x3DCCCCCD.

How an IEEE 754 number is laid out

Every binary IEEE 754 format has three fields: a sign bit (0 = positive), an exponent stored with a bias, and a fraction (also called the mantissa or significand field). For a normal number the value is

(−1)sign × 1.fraction × 2exponent − bias

The leading “1.” is not stored: it is the hidden bit, which gives one extra bit of precision for free. In this converter, bits are numbered from 0 at the right, so in single precision the sign is bit 31, the exponent bits 30–23 and the fraction bits 22–0.

FormatBits (sign / exponent / fraction)BiasExponent rangeLargest finiteSmallest normalSmallest subnormalMachine epsilonDecimal digits
Half precision (binary16) 16 (1 / 5 / 10) 15 -14 to 15 65504 0.000061035156 5.9604645e-8 2^−10 ≈ 0.0009765625 3 to 5
bfloat16 (not IEEE) 16 (1 / 8 / 7) 127 -126 to 127 3.3895314e+38 1.1754944e-38 9.1835496e-41 2^−7 ≈ 0.0078125 2 to 4
Single precision (binary32) 32 (1 / 8 / 23) 127 -126 to 127 3.4028235e+38 1.1754944e-38 1.4012985e-45 2^−23 ≈ 1.1920929e-7 6 to 9
Double precision (binary64) 64 (1 / 11 / 52) 1023 -1022 to 1023 1.7976931e+308 2.2250739e-308 4.9406565e-324 2^−52 ≈ 2.220446e-16 15 to 17

Values computed exactly by the same code as the converter and rounded to 8 significant digits. Decimal digits: guaranteed to survive decimal → binary → decimal, and needed for binary → decimal → binary. bfloat16 is not an IEEE 754 format (it comes from Google Brain for machine learning) but follows the same rules with float32’s exponent.

Worked example: −13.625 to single precision

  1. Sign: negative, so the sign bit is 1.
  2. Binary: 13 = 1101 and 0.625 = 0.101 (0.5 + 0.125), so 13.625 = 1101.1012.
  3. Normalize: 1101.101 = 1.101101 × 23.
  4. Exponent: 3 + 127 = 130 = 10000010.
  5. Fraction: the bits after the leading 1, padded to 23 bits: 10110100000000000000000.
  6. Result: 1 10000010 10110100000000000000000 = 0xC15A0000. The value is exact, so the rounding error is 0.

Worked example: 0x40490FDB to decimal

  1. Binary: 0 10000000 10010010000111111011011.
  2. Sign 0 (positive); exponent field 128, so the exponent is 128 − 127 = 1.
  3. Significand: 1 + 4788187 / 223 = 1.57079637050628662109375.
  4. Value: 1.57079637… × 2 = 3.1415927410125732421875, the single-precision value of π. It is about 8.7 × 10−8 larger than π.

Rounding, and why the error column matters

Most decimal fractions have no finite binary expansion, so the converter shows two things other tools leave out: the exact decimal value of the stored bits (every binary float has a finite decimal expansion) and the exact difference from what you typed. It also shows the gap to the next representable value (one ULP), which tells you how coarse the format is at that magnitude.

The conversion is done with exact integer arithmetic directly from your decimal string. That matters for single and half precision: the common shortcut of parsing to a double first and then narrowing (Math.fround(Number(s)) in JavaScript, (float)strtod(s) in C) rounds twice and can be off by one ULP when the input sits just above a halfway point. For example, 1.000000059604644775390625000000000001 must round up to 0x3F800001, but rounding through a double gives 0x3F800000.

Special values

ValueExponent fieldFraction fieldSingle precisionDouble precision
+0 / −0all 000x00000000 / 0x800000000x0000000000000000 / 0x8000000000000000
Subnormalall 0≠ 00x00000001 = 2−1490x0000000000000001 = 2−1074
+∞ / −∞all 100x7F800000 / 0xFF8000000x7FF0000000000000 / 0xFFF0000000000000
Quiet NaNall 1top bit 10x7FC000000x7FF8000000000000
Signaling NaNall 1top bit 0, rest ≠ 0e.g. 0x7FA00000e.g. 0x7FF4000000000000

Comparisons and familiar surprises

  • 0.1 + 0.2 ≠ 0.3 in double precision. The rounded sum is 0x3FD3333333333334 (prints as 0.30000000000000004) while 0.3 is 0x3FD3333333333333, one ULP below. Compare floats with a tolerance, not with ==.
  • +0 = −0. The two zeros have different bits but compare equal; they differ in results such as 1/(+0) = +∞ and 1/(−0) = −∞.
  • NaN ≠ NaN. Every comparison with NaN is false, including NaN == NaN, which is why x != x is a classic NaN test.
  • Bit order = value order. For positive finite numbers, a larger bit pattern read as an integer is a larger float; that is why the next value up is simply the bit pattern plus one.

The standard also defines quadruple precision (binary128: 1 + 15 + 112 bits) and decimal formats (decimal32, decimal64, decimal128) that store base-10 digits exactly; they are rare in coursework and not covered by this converter.

Need a specific width? See the dedicated pages for 16-bit half precision and 64-bit double precision. For integers, use the two’s complement calculator.

Frequently asked questions

What is IEEE 754?

IEEE 754 is the standard for floating-point arithmetic used by practically every CPU, GPU and programming language. It defines how a real number is stored as a sign bit, a biased exponent and a fraction (mantissa), how results are rounded, and the special values ±0, ±∞ and NaN. The 1985 edition defined single and double precision; the 2008 revision added half precision (binary16), quadruple precision (binary128) and decimal formats; the current edition is IEEE 754-2019. bfloat16, also offered by this converter, is not part of the standard: it is float32 cut to 16 bits, used in machine learning.

How do I convert a decimal number to IEEE 754 single precision?

Write the number in binary, normalize it to 1.f × 2e, store e + 127 in the 8 exponent bits, the first 23 bits of f (rounded to nearest, ties to even) in the fraction, and the sign in the top bit. For −13.625: binary 1101.101 = 1.101101 × 23, exponent 3 + 127 = 130 = 10000010, fraction 10110100000000000000000, sign 1, giving 0xC15A0000.

Why is 0.1 not exact in floating point?

0.1 in binary is 0.000110011001100…, a repeating fraction, just like 1/3 in decimal. Any finite number of bits must cut it off, so the stored value is the nearest representable number: 0.100000001490116119384765625 in single precision and 0.1000000000000000055511151231257827021181583404541015625 in double precision.

What is the exponent bias?

The exponent is stored as an unsigned number with an offset (the bias) of 2k−1 − 1 for k exponent bits: 15 for half precision, 127 for single and bfloat16, 1023 for double. The actual exponent is the stored field minus the bias, except for subnormals, which use 1 − bias.

What are subnormal (denormal) numbers?

When the exponent field is 0 and the fraction is not, the number is subnormal: it has no hidden leading 1 and uses the fixed exponent 1 − bias (−126 for single precision). Subnormals fill the gap between zero and the smallest normal number, so tiny results lose precision gradually instead of jumping to zero.

How are NaN and infinity stored?

Both have every exponent bit set to 1. A zero fraction means infinity (the sign bit picks +∞ or −∞); a nonzero fraction means NaN. In single precision, +∞ is 0x7F800000, −∞ is 0xFF800000 and the usual quiet NaN is 0x7FC00000.

What does “round to nearest, ties to even” mean?

It is the default rounding mode: the result is the representable value closest to the exact one, and when the exact value lies exactly halfway between two, the one whose last fraction bit is 0 wins. This avoids the upward bias of always rounding halves up. The converter lets you try the other four modes too.

Sources

  • IEEE Std 754-2019, IEEE Standard for Floating-Point Arithmetic, IEEE, 2019 (revision of IEEE 754-2008 and IEEE 754-1985).