Hex to Float Converter
Hex to float converter: write the hex as 32 or 64 bits, read the sign, the exponent and the mantissa, and rebuild the number. 40490FDB is 3.1415927 as a single and 400921FB54442D18 is pi as a double. Pick the byte order, and the table shows the exact stored value.
| Sign | 0 (positive) |
|---|---|
| Exponent field | 10000000 = 128, unbiased 1 |
| Mantissa field | 10010010000111111011011 |
| Class | normal |
| Exact stored value | 3.1415927410125732421875 |
Hex to float: split the bits into sign, exponent and mantissa
To convert hex to a floating point number, write the hex digits as bits and cut them into three fields: one sign bit, an exponent, and a mantissa. A 32-bit float uses 1, 8 and 23 bits and a 64-bit double uses 1, 11 and 52. The value is the sign, times 1 followed by the mantissa as a binary fraction, times 2 raised to the exponent minus the bias.
The bias is 127 for single precision and 1023 for double precision. It exists so the exponent field can be stored as a plain unsigned number while still meaning both negative and positive powers of two. The layout is defined by IEEE 754, and every mainstream processor and language follows it, which is why the same hex reads the same number everywhere once the byte order is settled.
Worked example: 40490FDB is 3.1415927
Start with 40490FDB. Written as 32 bits it is 0 10000000 10010010000111111011011. The sign bit is 0, so the number is positive. The exponent field 10000000 is 128, and removing the bias of 127 leaves 1. The mantissa field is the integer 4,788,187, and as a fraction of 2^23 (8,388,608) it is 0.5707964.
| Step | Value |
|---|---|
| Hex to bits | 0 10000000 10010010000111111011011 |
| Sign | 0, so the sign factor is +1 |
| Exponent field minus bias | 128 − 127 = 1 |
| Significand, 1 plus the mantissa fraction | 1 + 4788187 ÷ 8,388,608 = 1.57079637 |
| Multiply by 2 to the exponent | 1.57079637 × 2^1 = 3.14159274 |
| Exact stored value | 3.1415927410125732421875 |
The last row is the point of showing it: pi is not stored exactly, and the nearest single-precision number is 3.1415927410125732421875, a little larger than pi. The 64-bit version, 400921FB54442D18, is closer and prints as 3.141592653589793.
Single or double precision: the length of the hex decides
There is no marker in the hex that says which width it is. The length is the only clue. Eight hex digits are four bytes, a single, and sixteen are eight bytes, a double. Any other length is not a float, and the converter says so with the byte count it found instead of padding or cutting the value.
| Property | Single (32-bit) | Double (64-bit) |
|---|---|---|
| Hex digits | 8 | 16 |
| Sign, exponent, mantissa bits | 1, 8, 23 | 1, 11, 52 |
| Exponent bias | 127 | 1023 |
| Largest finite value | 3.4028235e+38 | 1.7976931348623157e+308 |
| Smallest normal value | 1.1754944e-38 | 2.2250738585072014e-308 |
| Smallest subnormal value | 1e-45 | 5e-324 |
| Gap between 1 and the next number | 2^−23 = 1.1920929e-7 | 2^−52 = 2.220446049250313e-16 |
| Decimal digits that always survive | 6 | 15 |
The 16-bit half-precision format and the 128-bit quad format also exist, but their lengths (2 and 16 bytes) are not handled here, and 16 bytes would be refused. If your value has 4 or 8 bytes, it is almost certainly one of the two above.
Byte order: DB 0F 49 40 and 40 49 0F DB are the same float
The hex 40490FDB is the number written most significant byte first, the way you would write it on paper. A computer writes it to memory in the order its processor uses. Intel and AMD processors, and ARM chips in their usual configuration, are little-endian, so the least significant byte comes first and the same float is stored as DB 0F 49 40. Network protocols and many file formats use big-endian, where the bytes are in reading order.
| Value | Number as written | Little-endian memory | Misread if the order is wrong |
|---|---|---|---|
| pi (single) | 40490FDB | DB 0F 49 40 | -40331460000000000 |
| 1.0 (single) | 3F800000 | 00 00 80 3F | 4.6006e-41 |
| 123.45 (single) | 42F6E666 | 66 E6 F6 42 | 5.4534347e+23 |
A misread rarely looks like an error. It is a valid float, usually an absurdly large or tiny one, such as the -40331460000000000 in the first row. When a value from a dump looks wrong by dozens of orders of magnitude, reverse the bytes before suspecting the data. The Little-endian bytes option above does the reversal.
Zero, infinity and NaN in hex
Two exponent fields are reserved. All zeros means zero or a subnormal number, and all ones means infinity or NaN. The mantissa then tells them apart: zero for infinity, anything else for NaN. The sign bit still counts, so there is a negative zero (80000000) that compares equal to the positive one but divides to a different infinity.
| Hex | Meaning | Value |
|---|---|---|
| 00000000 | positive zero | 0 |
| 80000000 | negative zero | -0 |
| 7F800000 | positive infinity | Infinity |
| FF800000 | negative infinity | -Infinity |
| 7FC00000 | quiet NaN | NaN |
| 7F800001 | signaling NaN | NaN |
| 7F7FFFFF | largest finite single | 3.4028235e+38 |
| 00800000 | smallest normal single | 1.1754944e-38 |
| 007FFFFF | largest subnormal single | 1.1754942e-38 |
| 00000001 | smallest subnormal single | 1e-45 |
NaN has many encodings, because any non-zero mantissa with an all-ones exponent qualifies. By the usual convention a set top mantissa bit (7FC00000) is a quiet NaN and a clear one (7F800001) is a signaling NaN. Programs treat all of them as not-a-number, and equality comparisons with NaN are false, even against itself.
Subnormal numbers fill the gap near zero
When the exponent field is 0, the number has no implicit leading 1. The value is the mantissa fraction times 2 to the power of −126 (single) and the digits near the smallest values lose precision gradually instead of dropping to zero. The converter marks such a value as subnormal. The step between neighbours there is the smallest subnormal, 00000001, which is 1e-45 for a single and 5e-324 for a double.
Hex values worth recognizing
A few single-precision patterns turn up so often in dumps and firmware that they are worth knowing on sight. Powers of two have a mantissa of zero and differ only in the exponent, so 3F800000 is 1, 40000000 is 2 and 3F000000 is a half. Whole numbers show up as a short mantissa with trailing zeros: 42C80000 is exactly 100. Values like 0.1 never terminate in binary, so they end in a repeating pattern that is rounded, as in CD at the end of 3DCCCCCD.
| Hex | Value | Note |
|---|---|---|
| 3F800000 | 1 | 1 |
| 40000000 | 2 | 2 |
| 3F000000 | 0.5 | one half |
| C0000000 | -2 | minus 2 |
| 41200000 | 10 | 10 |
| 42C80000 | 100 | 100 |
| 449A5000 | 1234.5 | 1,234.5 |
| 3DCCCCCD | 0.1 | 0.1, the nearest single |
| 3EAAAAAB | 0.33333334 | 1/3, the nearest single |
| 40490FDB | 3.1415927 | pi, the nearest single |
| 402DF854 | 2.7182817 | e, the nearest single |
Why the exact value is longer than the number you expect
Binary fractions can only be sums of powers of two, and 0.1 is not one. The stored float is therefore the nearest value that is, and writing that value out in decimal gives a long tail. The single 3DCCCCCD is exactly 0.100000001490116119384765625, and the double 3FB999999999999A is 0.1000000000000000055511151231257827021181583404541015625. Both print as 0.1 in most languages because 0.1 is the shortest decimal that rounds back to the stored value.
That is why the result box shows the shortest form and the table under it shows the exact one. If you compare floats from different sources, compare them as hex or with a tolerance, not as typed decimals. The well-known 0.1 + 0.2 = 0.30000000000000004 in JavaScript comes from the same effect in 64-bit arithmetic.
Floats in Modbus registers and device payloads
Industrial devices often send a float as two 16-bit registers. The number 123.45 as a single is 42F6E666, so the registers hold 42F6 and E666. Whether the high word comes first is up to the device, and manuals describe it with names such as ABCD, CDAB, BADC and DCBA for the four possible byte and word orders. Joining the registers in the wrong order yields a valid but wrong float.
| Order | Joined hex | Float value |
|---|---|---|
| High word first (ABCD) | 42F6E666 | 123.45 |
| Low word first (CDAB) | E66642F6 | -2.7184488e+23 |
The practical test is to try the orders and see which gives a plausible reading, such as a temperature of 123.45 instead of an exponent of 10 to the 23rd power. Then confirm against the device manual, because a wrong order that looks plausible for one reading can still be wrong for others.
Reading floats from a hex dump or a debugger
A memory dump shows bytes, not types, so a float is something you recognize and then decode. Take four bytes, decide the order (memory order on a PC is little-endian), turn them around if needed and paste the result here. Eight bytes from a dump of a double work the same way with 16 digits. In a little-endian dump the last of the four bytes holds the sign and the top of the exponent, so ordinary positive numbers of moderate size often end in 3F, 40, 41 or 42, which covers values from about 0.5 up to a few hundred. Text, by contrast, is the job of the hex code decoder.
How many digits of a float you can trust
A single stores about seven significant decimal digits and a double about sixteen. In concrete terms, every decimal number with up to 6 digits survives a trip through a single and back, and up to 15 digits through a double. Integers are exact up to 2^24 = 16,777,216 for singles and 2^53 = 9,007,199,254,740,992 for doubles. Above that the gaps exceed 1: the integer 16,777,217 does not exist as a single and becomes 16,777,216.
Hex to float in JavaScript and PowerShell
JavaScript reads floats from bytes with a DataView, where the bytes of the hex are written with setUint32 or setBigUint64 and read back as a float. In PowerShell, BitConverter turns a byte array into a single. Both give 3.1415927 for 40490FDB; see DataView on MDN and BitConverter.ToSingle.
const view = new DataView(new ArrayBuffer(4));
view.setUint32(0, 0x40490fdb);
console.log(view.getFloat32(0)); // 3.1415927410125732
// 64-bit
const d = new DataView(new ArrayBuffer(8));
d.setBigUint64(0, 0x400921fb54442d18n);
console.log(d.getFloat64(0)); // 3.141592653589793[BitConverter]::ToSingle([byte[]](0xDB, 0x0F, 0x49, 0x40), 0)
[BitConverter]::ToDouble([byte[]](0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40), 0)The JavaScript output is the full double that holds the single, which is why it prints more digits than the 3.1415927 of the converter; the converter shows the shortest text that identifies the single.
When four bytes are not a float
Any four bytes decode as some float, so a successful result is not proof that the data is one. A 32-bit integer, an IPv4 address, four ASCII characters and a color all fit in the same eight hex digits. Check the context: a plausible magnitude, a known field type, or a fixed format. For an integer reading, use the hex to decimal converter, and for text the hex decoder. For the reverse direction, see float to hex.
Typical mistakes when converting hex to float
The most common mistake is the byte order, covered above. Next is the width: a value copied from a double log and read as a single, or the reverse, gives nonsense, and the length check catches only the cases where the digit count differs. Padding a short hex with zeros on the right would shift the exponent, so this converter refuses short input and shows the error instead. A hex string with an odd number of digits is missing a digit, and a prefix such as 0x or a leading backslash-x is accepted but not part of the value. Finally, remember that the printed decimal is rounded for display, so two different floats can look the same when printed with only a few digits.
Questions about converting hex to float
What is 3F800000 as a float?
1.0. The sign bit is 0, the exponent field is 127 (01111111), which is 0 after removing the bias of 127, and the mantissa is all zeros, so the value is 1.0 × 2^0.
How do I know whether hex is a 32-bit or a 64-bit float?
Count the bytes. Four bytes (8 hex digits) is single precision, and eight bytes (16 hex digits) is double precision. The converter picks the width from the length unless you set it, and it refuses any other length.
Why does the same hex give a different number when I reverse the bytes?
Because the first byte in memory is read as the most significant one only on big-endian systems. Most desktop and phone processors store floats little-endian, so DB 0F 49 40 in a memory dump is the number 40490FDB. Tick Little-endian bytes to read it that way.
What does 7FC00000 mean?
NaN, not a number. The exponent field is all ones and the mantissa is not zero. The top mantissa bit marks a quiet NaN, which propagates through arithmetic without raising an exception.
Can I convert hex to a float by hand?
Yes, with the three fields. Write the hex as bits, split them 1, 8 and 23 for single precision, subtract 127 from the exponent field, put a 1 in front of the mantissa as 1.xxx and multiply by 2 to the unbiased exponent. The worked example above does this for 40490FDB.
Is the displayed value exact?
The exact stored value is shown in the table under the result, written out digit by digit. The value in the output box is the shortest decimal that reads back as the same float, which is what most programming languages print.
