IEEE 754 Converter
Convert decimal numbers to IEEE 754 single and double precision floating point and back, with the sign, exponent and mantissa bits, the hex value and the exact stored value.
Input
Output
Readme
What is IEEE 754?
IEEE 754 is the standard nearly every computer uses for floating point numbers: float (single precision, 32 bits) and double (double precision, 64 bits) in C, Java and C#, f32/f64 in Rust, and every Number in JavaScript. A float stores a number in three fields: a sign bit, an exponent that sets the scale, and a mantissa (the fraction) that holds the significant binary digits. Most decimal fractions, like 0.1, have no exact binary form, so a float stores the nearest value it can. This converter shows those bits and the exact value they hold.
Using the converter
- Type a decimal number such as
0.1,-2.5e-3or6.02e23, orNaNorInfinity, to see its bits. - Or type the hex bits of a float, such as
0x3DCCCCCD, with or without0x, to see the number they stand for. - Or click any bit to flip it: the decimal and hex fields follow.
- Switch between 32-bit and 64-bit: the number you typed is kept and converted to the other format.
Reading the results
- Exact stored value: the value the float really holds, written out in full. Every binary float is a finite decimal, so this is exact, however long it gets.
- Conversion error: the stored value minus the number you typed, rounded to 17 significant digits. It's 0 when the number fits exactly, like 0.5 or 3.75.
- Sign: 0 for positive, 1 for negative. There is a negative zero too.
- Exponent and Stored exponent: the power of two the significand is scaled by, and the biased value kept in the exponent field (the exponent plus 127 for single, plus 1023 for double).
- Significand: 1 plus the fraction for normal numbers (the leading 1 isn't stored), or 0 plus the fraction for subnormal ones.
- Class: normal; subnormal (numbers so small that the exponent field is 0, which lose precision gradually instead of jumping to zero); zero; infinity; or NaN, "not a number", which is quiet when the top mantissa bit is set and signaling when it isn't.
- Binary: all bits, grouped as sign, exponent and mantissa.
| Single (32-bit) | Double (64-bit) | |
|---|---|---|
| Sign | 1 bit | 1 bit |
| Exponent | 8 bits, bias 127 | 11 bits, bias 1023 |
| Mantissa | 23 bits | 52 bits |
| Significant decimal digits | about 7 | about 15 to 16 |
| Largest finite value | about 3.4 × 10^38 | about 1.8 × 10^308 |
| Smallest positive value | about 1.4 × 10^-45 | about 4.9 × 10^-324 |
Examples
- 0.1 as a single is
0x3DCCCCCD, which stores 0.100000001490116119384765625, a conversion error of about 1.49e-9. - 0.1 as a double is
0x3FB999999999999A, which stores 0.1000000000000000055511151231257827021181583404541015625. - 1 is
0x3F800000as a single; flipping the sign bit gives0xBF800000, which is -1. - 16777217 becomes 16777216 as a single: above 2^24, singles can't hold every whole number.
- 1e39 is too large for a single and becomes infinity, while a double holds it easily.
How it works
The browser does the rounding with its own IEEE 754 arithmetic (a DataView), which rounds to the nearest float and breaks ties toward the even one. The exact values are worked out with BigInt. A typed number is first rounded to the nearest double; for 32 bits that double is then rounded to a single, as JavaScript's Math.fround does. For a very few numbers that lie almost exactly halfway between two singles, rounding twice can land one step away from rounding the decimal straight to a single. After you edit the hex or the bits, the decimal field shows the shortest number that reads back as exactly those bits. Everything runs in your browser.
Features
- 32-bit (single) and 64-bit (double) precision
- Decimal to bits and hex bits to decimal, both ways
- Clickable bits, colored by sign, exponent and mantissa
- The exact stored value and the conversion error
- Exponent, stored exponent, significand and class, including subnormals, infinities and quiet and signaling NaN
- Runs in your browser