NewAI Part GeneratorFree to get started
FREE TOOL

IEEE 754 floating-point converter

The IEEE 754 floating-point converter below shows the sign, exponent and fraction bits of a float32 or float64, converts decimal to hex and hex to decimal, and reads out the exact value that is stored. Click any bit to flip it.

Format
Enter
Examples

Click any bit to flip it. Bit 31 is on the left.

SignExponentFraction

binary32 bit pattern

0x3DCCCCCD

Normal, reads back as 0.1

Value read back
0.1
Bytes in little-endian memory
CD CC CC 3D
Class
Normal
Sign bit
0 (positive)
Exponent field
123 (bias 127)
Exponent e
-4
Fraction field
0x4CCCCD
Significand
1.60000002384185791015625
C hex float (%a)
0x1.99999ap-4
Spacing here (1 ULP)
7.45058e-9
Machine epsilon of binary32
1.19209e-7 (2^−23)
Next float up
0.10000001 (0x3DCCCCCE)
Next float down
0.099999994 (0x3DCCCCCC)
Error (stored − input)
1.49012e-9
Error in ULPs
0.2
Relative error
1.49e-8

The input needs more significant bits than binary32 has, so it was rounded to the nearest float (ties to the even significand, the IEEE default).

Exact value stored, every digit

0.100000001490116119384765625

How do you convert decimal to IEEE 754?

Write the number as ±1.f × 2e, then store the sign, e plus the bias (127 for float32, 1023 for float64), and the bits of f rounded to the nearest float. 0.1 is 1.6 × 2−4, so as a float32 the exponent field is 123 and the pattern is 0x3DCCCCCD, which holds 0.100000001490116119384765625.

IEEE 754 floating-point formula

A floating-point number is a binary version of scientific notation, split into three fields: one sign bit, an exponent field and a fraction field.

value = (−1)ˢ × 1.f × 2^(E − bias)
s
sign bit, 1 for negative
E
the stored exponent field
f
the stored fraction, read as binary digits after the point
bias
127 for float32, 1023 for float64

Two exponent field values are reserved. All zeros means zero or a subnormal value, with no implicit leading 1:

value = (−1)ˢ × 0.f × 2^(1 − bias)

All ones means infinity when the fraction is zero and NaN otherwise. A decimal input rarely has an exact binary form, so it is rounded to the nearest float, with exact ties going to the float whose last significand bit is 0. This floating-point calculator does that on exact integer arithmetic, so a decimal never takes a detour through a double on its way to a float32, which would round twice.

Worked examples

Example 1: 0.1 as a float32

0.1 = 1.6 × 2⁻⁴, so e = -4 and the exponent field is -4 + 127 = 123. The fraction 0.6 × 2²³ = 5033164.8 rounds to 5033165, or 0x4CCCCD. Together the fields give 0x3DCCCCCD. The value stored is 0.100000001490116119384765625, an error of 1.49e-9 or 0.2 ULP.

Example 2: reading 0xC0490FDB

In binary the top bit is 1, so the value is negative. The next 8 bits are 128, giving e = 1. The significand is 1.57079637050628662109375, so the value is −1.57079637050628662109375 × 2 = -3.1415927 (exactly -3.1415927410125732421875). This is −π as a float32.

Example 3: where integers run out

16,777,217 is 2²⁴ + 1 and needs 25 significant bits, one more than a float32 has. It is an exact tie between two floats, so it rounds to the one with the even significand: 16777216 (0x4B800000). A float64 hits the same wall at 2⁵³ + 1, where 9,007,199,254,740,993 becomes 9007199254740992. A counter held in a float32 eventually stops increasing.

float32 and float64 format parameters

The limits every float.h is built from, computed from the bit patterns themselves.

Parameterfloat32 (binary32)float64 (binary64)
Total bits3264
Exponent bits811
Fraction bits2352
Precision p24 bits53 bits
Exponent bias1271023
Normal exponent range-126 to +127-1022 to +1023
Largest finite3.4028235e+381.7976931348623157e+308
Smallest normal1.1754944e-382.2250738585072014e-308
Largest subnormal1.1754942e-382.225073858507201e-308
Smallest subnormal1e-455e-324
Machine epsilon1.1920929e-72.2204460492503131e-16
Unit roundoff5.96046448e-81.1102230246251565e-16
Decimal digits kept615
Digits to round-trip917
All integers up to16,777,2169,007,199,254,740,992
C typefloatdouble

Floating-point to hex: common values

Decimal inputs are rounded to the nearest float. π is entered to 20 decimal places.

Valuefloat32 hexfloat64 hex
+00x000000000x0000000000000000
−00x800000000x8000000000000000
10x3F8000000x3FF0000000000000
−10xBF8000000xBFF0000000000000
0.50x3F0000000x3FE0000000000000
20x400000000x4000000000000000
0.10x3DCCCCCD0x3FB999999999999A
0.20x3E4CCCCD0x3FC999999999999A
0.30x3E99999A0x3FD3333333333333
100x412000000x4024000000000000
1000x42C800000x4059000000000000
π0x40490FDB0x400921FB54442D18
+∞0x7F8000000x7FF0000000000000
−∞0xFF8000000xFFF0000000000000
Quiet NaN0x7FC000000x7FF8000000000000

Using floats on real hardware

  • Do not compare floats with ==. Compare the difference to a tolerance scaled to the values involved, since the spacing of floats grows with magnitude.
  • Print enough digits to keep the bits: 9 significant digits for float32 and 17 for float64. For an exact, compact form use C’s hex float (%a).
  • Long sums drift. Adding a small value to a large running total loses the low bits of the small value each time. Keep time and counters in integers, or use a compensated sum.
  • Check whether your FPU handles double in hardware. Many microcontroller FPUs are single-precision only, so a stray double constant such as 1.0 instead of 1.0f pulls in software floating point.
  • Multi-byte floats have a byte order. On a little-endian processor the bytes of 0.1f sit in memory as CD CC CC 3D, which is what a memory dump or a UART log shows. Use the little-endian option to read those directly.
  • Subnormals are slow on some processors, and flush-to-zero modes replace them with zero. Both can change results near the bottom of the range.

This IEEE 754 calculator covers binary32 and binary64 with the default rounding mode. The quiet and signaling labels follow the IEEE 754-2008 convention for the top fraction bit, which some older MIPS processors reverse.

Glossary

Biased exponent
The stored exponent field: the true exponent plus 127 (float32) or 1023 (float64), so it is always non-negative.
Fraction
The stored bits after the binary point of the significand, also called the trailing significand.
Significand
The full number multiplied by the power of two: 1.f for normal values and 0.f for subnormal values.
ULP
Unit in the last place: the value of the lowest significand bit, which is the spacing between neighboring floats at that magnitude.
Subnormal
A value below the smallest normal float, with an exponent field of 0 and no implicit leading 1.
NaN
Not a number: the result of an invalid operation such as 0 ÷ 0, stored with all exponent bits set and a nonzero fraction.
roundTiesToEven
The IEEE default rounding: to the nearest float, and on an exact tie to the one whose last significand bit is 0.

Related guides

Frequently asked questions

What is 0.1 in IEEE 754 single precision?

0x3DCCCCCD. The stored value is 0.100000001490116119384765625, because 0.1 has no finite binary form. As a double it is 0x3FB999999999999A.

How do you convert a float to hex?

Round the number to the nearest float, then read the sign, exponent and fraction fields together as one hex pattern. 0.1 is 0x3DCCCCCD as a float32 and 0x3FB999999999999A as a float64. This IEEE 754 converter does the rounding on exact integer arithmetic.

How do you convert a hex pattern to a float?

Split the pattern into its sign, exponent and fraction fields, then, unless the exponent field is all zeros or all ones, apply value = (−1)ˢ × 1.f × 2^(E − bias). 0xC0490FDB has the sign bit set and an exponent field of 128, which makes it -3.1415927. The hex to float converter above takes any pattern, including little-endian memory dumps.

Why does 0.1 + 0.2 not equal 0.3?

None of the three has an exact binary form, so each is stored rounded: as doubles, 0.1 is 0x3FB999999999999A, 0.2 is 0x3FC999999999999A and 0.3 is 0x3FD3333333333333. The rounding errors of 0.1 and 0.2 do not cancel, so their sum lands on the neighboring double, 0.30000000000000004.

How many decimal digits does a float have?

A float32 reliably keeps 6 decimal digits and a float64 keeps 15. To print a value so that it reads back to the same bits, use 9 significant digits for float32 and 17 for float64.

What is machine epsilon?

The gap between 1 and the next larger float: 2^−23 (1.19209e-7) for float32 and 2^−52 (2.22045e-16) for float64. The maximum relative rounding error, or unit roundoff, is half of that.

What are subnormal numbers?

Values smaller than the smallest normal float (1.1754944e-38 for float32), stored with an exponent field of zero and no implicit leading 1. They let values fade gradually to zero at the cost of precision.

How are NaN and infinity stored?

Both have every exponent bit set. A fraction of zero means infinity, and the sign bit picks + or −. Any nonzero fraction is NaN, with the top fraction bit set for a quiet NaN and clear for a signaling NaN.

What is the largest integer a float can store exactly?

Every integer up to 2^24 (16,777,216) fits a float32, and every integer up to 2^53 (9,007,199,254,740,992) fits a float64. Above that some integers are skipped, although every float that large is still a whole number.

What is the difference between mantissa, significand and fraction?

The significand is the full 1.xxx number including the implicit bit. The fraction (the IEEE standard calls it the trailing significand) is the part actually stored. Mantissa is the older informal word for either.

More free PCB tools

See all free electronics tools →

Sources

Design the whole board, not one number

ProtoFlow is free AI PCB design software: describe a circuit and get a schematic with real parts, PCB layout with an autorouter, SPICE simulation and Gerber files. Native KiCad, Altium and EAGLE import and export. Free on macOS, Windows and Linux.

Get for Mac

Free to start. No card required.