Skip to content
Aarrange

Float to Hex

Paste decimal floats, one per line. Get the IEEE 754 hex for float or double, rounded exactly. Nothing leaves your browser.

Also: All formats, Hex to Float, Float to Bin

0
Numbers
0
Rounded
0
Errors
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .
On this page

About Float to Hex

Updated

Float to Hex turns decimal numbers into the hex bits of an IEEE 754 float. That is what you need for a C array, an EEPROM, a Modbus register, a network packet or a unit test. Paste one number or a whole list.

Each number is rounded once, to the nearest float, the same way a compiler does it. When a number is rounded, Results also shows the exact value that is stored and the rounding error. So you can see that 0.1 becomes 0.100000001490116119384765625.

The same tool, set up for other jobs: IEEE 754 Converter, Hex to Float, Float to Binary. For whole numbers in any base, use the Number Base Converter.

How to use it

  1. Paste decimal numbers, one per line, or load a file. Tabs, semicolons and a comma with a space after it also split a line.
  2. Pick the Format: 16-bit half, bfloat16, 32-bit single, 64-bit double or 128-bit quad. It is in the Result header. On a phone it is under More.
  3. Check From and To, next to Convert. On a phone they are under More.
  4. Press Convert (Alt C). Results shows each answer and how much it was rounded. When a number is rounded, the Value column shows the exact value that is stored. A long value is cut short there, and Bits shows all of it. Output has only the answers, for Copy and Download.
  5. Open Bits to see the sign, exponent and mantissa of one number. Click a bit to flip it, or step to the next float up or down. Steps shows the work by hand.
  6. Swap (Alt S) puts the answers in the editor and turns From and To around, so you can check the way back.

How to convert a float to hex by hand

Take 85.125 to 32-bit:

Float to hex
1. Binary:      85.125 = 1010101.001
2. Normalise:   1.010101001 x 2^6
3. Exponent:    6 + 127 = 133 = 10000101
4. Mantissa:    010101001 then zeros to 23 bits
5. Together:    0 10000101 01010100100000000000000
6. Hex by 4:    0100 0010 1010 1010 0100 0000 0000 0000
                4    2    A    A    4    0    0    0   = 42AA4000

85.125 ends in binary, so it is exact. A number like 0.1 does not, and step 4 must round the bits after the 23rd: to the nearest, and on an exact half to the even one.

Common values

Float and double in hex
Value        32-bit float   64-bit double
0            00000000       0000000000000000
1            3F800000       3FF0000000000000
-1           BF800000       BFF0000000000000
0.5          3F000000       3FE0000000000000
0.1          3DCCCCCD       3FB999999999999A
3.14159265   40490FDB       400921FB53C8D4F1
100          42C80000       4059000000000000

Common errors

A decimal comma

In much of Europe, one and a half is written 1,5. Other converters read it as 1 or as 0, with no warning. This tool marks the comma. A comma with a space after it splits two numbers, so a list such as 0.1, 0.2 still works.

Invalid
1,5
Decimal comma. Write 1.5 with a point. For two numbers, put a space
after the comma.
Fixed
1.5

An exponent with no digits

A number copied from a log can lose its end. The tool marks the e.

Invalid
6.02e
Exponent has no digits. Put the power of ten after the e: 1e5 or 2.5e-3.
Fixed
6.02e23

A whole number that is not exact

This one is not an error, but it surprises people. A 32-bit float holds every whole number up to 16,777,216 (2^24). Past that, only every second one. 16777217 is stored as 16777216, and the tool says so in a note.

Float to hex in code

Float to hex
C           float f = 0.1f; uint32_t u; memcpy(&u, &f, sizeof u);
            printf("%08X\n", u);                 // 3DCCCCCD
Python      struct.pack(">f", 0.1).hex()         # '3dcccccd'
            struct.pack(">d", 0.1).hex()         # '3fb999999999999a'
Java        Integer.toHexString(Float.floatToIntBits(0.1f))
C#          BitConverter.SingleToInt32Bits(0.1f).ToString("X8")

Float to hex resources

Float to hex FAQ

How do I convert a float to hex?

A float to hex conversion does not write the number in base 16. It shows the bits the float is stored in, as hex. For 32-bit: write the number as 1.xxx × 2^e, store e + 127 in 8 bits, keep 23 bits after the point, and put the sign in front.

For -10.5: it is 1.3125 × 2^3. The sign is 1, the exponent 3 + 127 = 130 = 10000010, the mantissa 0101 and zeros. Together: C1280000. Paste a number here and open Steps to see it done for yours.

What is 0.1 in hex as a float?

3DCCCCCD as a 32-bit float and 3FB999999999999A as a 64-bit double. Both are rounded: 0.1 has no end in binary. The 32-bit value is 0.100000001490116119384765625.

What is 1.0 in hex as a float?

3F800000 in 32-bit and 3FF0000000000000 in 64-bit. The sign and mantissa are zero. The exponent field holds the bias, 127, which is 01111111 in binary. These 8 bits fill bits 30 to 23, after the sign bit, so the hex starts with 3F8.

How do I convert a double to hex?

Set Format to 64-bit. A double has 11 exponent bits with a bias of 1023 and 52 mantissa bits, so its hex has 16 digits: 3.14159 is 400921F9F01B866E.

Why does my hex have the bytes in the wrong order?

Because x86 and ARM store the low byte first. In memory, in a file or on a wire from such a machine, 1.0 is 00 00 80 3F. Set Byte order to Little-endian to get the bytes in that order.

How do I convert a float to hex in Python or C?

Python: struct.pack('>f', 0.1).hex() gives '3dcccccd'; use '>d' for a double and '<f' for little-endian. C: copy the float into a uint32_t with memcpy and print it with %08X.

Are my numbers sent anywhere?

No. Every number is converted in your browser, with exact BigInt math. Nothing is uploaded, and there are no ads or cookie walls. You can check this in your browser's network tab while you use it.