How to use the Float to Hex Converter tool
- Enter the decimal number in Number. Exponent notation such as 2.5e-3 and the words Infinity and NaN are allowed.
- Select Convert, or select Example to convert -13.25.
- Read the eight hex digits after 0x. The leftmost digit contains the sign bit.
- Select Copy and paste the pattern where you need it.
What float to hex conversion does
A single-precision float has 1 sign bit, 8 exponent bits with a bias of 127, and 23 fraction bits. The tool first reads your text as a 64-bit double, then narrows it to 32 bits with round-to-nearest, ties-to-even, the same result as a cast to float in C. The 32 bits are printed as one hexadecimal number.
Unlike a double, the fields of a float do not fall on hex digit boundaries. Sign and exponent take 9 bits, so the third hex digit mixes the last exponent bit with the first three fraction bits. To read a pattern by hand, expand it to binary first.
Worked example: -13.25 to 0xC1540000
13.25 is 1101.01 in binary, or 1.10101 x 2^3. The sign bit is 1 because the number is negative. The exponent field is 3 + 127 = 130, which is 10000010. The fraction is 10101 followed by eighteen zeros. Joined together and regrouped in fours, the bits read 1100 0001 0101 0100 0000 0000 0000 0000, which is C1540000.
-13.25 -> 0xC1540000
1 -> 0x3F800000
0.1 -> 0x3DCCCCCD
123.456 -> 0x42F6E979
16777217 -> 0x4B800000
1e40 -> 0x7F800000
NaN -> 0x7FC00000Precision loss you can see in the hex
A float keeps 24 significant bits, about 7 decimal digits. 0.1 becomes 0x3DCCCCCD, which is really 0.100000001490116. 16777217 becomes 0x4B800000, the pattern for 16777216, because odd integers above 2^24 cannot be stored.
Range is limited too. 3.4028235e38 is the largest float, 0x7F7FFFFF, while 3.4028236e38 already rounds to Infinity, 0x7F800000. At the small end, 1e-40 is a subnormal, 0x000116C2, and 1e-46 underflows to 0x00000000.
Formats the Number field accepts
Whitespace around the value is trimmed. Everything else must be plain decimal notation, or the tool answers Enter a number, Infinity or NaN.
- Accepted: 42, +7, -0.75, .5, 1E2, 6.02214076e23.
- Accepted: inf, -inf, Infinity and NaN, in upper or lower case.
- Rejected: 0x10, 1_000, 1,000 and text mixed with digits such as 12abc.
- -0 is preserved and converts to 0x80000000.
- NaN always converts to the quiet NaN 0x7FC00000. You cannot choose a payload or a sign.
Frequently asked questions
How do I convert a float to hex in Python or C?
In Python, struct.pack('>f', x).hex() gives the same eight digits. In C, memcpy the float into a uint32_t and print it with an 8-digit hex format. Avoid pointer casts, which break strict aliasing rules.
Why does my debugger show 00 00 54 C1 for -13.25?
The debugger lists bytes in memory order, and x86 and most Arm targets are little-endian, so the least significant byte comes first. The tool prints the value most significant byte first: C1 54 00 00. Reverse one to get the other.
What is 1.0 as a hex float pattern?
It is 0x3F800000. The sign is 0, the exponent field is 127 (01111111) for 2^0, and the fraction is zero. Doubling the value adds one to the exponent, so 2.0 is 0x40000000.
Why do 16777216 and 16777217 give the same hex?
A float's significand has 24 bits, so above 2^24 only even integers are representable. 16777217 lies halfway between two floats and the tie rule picks the even one, 16777216. Use the Double to Hex Converter when you need more digits.
How do I turn the hex back into a number?
Paste the eight digits into the Hex to Float Converter. Because the pattern is exact, the round trip returns the float's true value, which can show more digits than you typed: 0x3DCCCCCD comes back as 0.10000000149011612.
Is the conversion done on my device?
Yes. The number is parsed and encoded by a few lines of JavaScript in the page, using the browser's own IEEE 754 arithmetic. No value you type is sent anywhere.