EditSafely

Convert Float to Hexfloat

Create a hexfloat number from a floating-point number.

Runs on your device, nothing uploaded

Precision
Exponent style
Letters
Try:

0 chars · 0 lines

Output

Create a hexfloat number from a floating-point number.

Type or paste above to see the result here.

Example: Twelve

What you paste never leaves this tab

Convert Float to Hexfloat is JavaScript that your browser has already downloaded, and it does the whole job on your own machine. On a normal site, whatever you type in is sent to a server that can log it, cache it or keep it. Here it is read and transformed inside this tab and nowhere else.

  • No upload
  • No length limit
  • Works offline once loaded
  • Nothing stored or logged

How to use Convert Float to Hexfloat

  1. 1. Type the number. Enter a decimal like 0.1, 12 or -0.5. Infinity and NaN give inf and nan with a note, as C prints them.
  2. 2. Pick precision and style. Precision double writes 13 hex fraction digits; float writes 6 and adds the f suffix, so 0.1 becomes 0x1.99999ap-4f. Exponent style C writes p+3, Java writes p3. Letters switches to 0X1.8P+3.
  3. 3. Copy the literal. Copy the hex float literal into C, C++ or Java source; the exact value and the IEEE bits are listed under it.

When to use Convert Float to Hexfloat

Convert Float to Hexfloat produces the %a style literal that represents a floating-point value exactly, with no decimal approximation. Numeric library authors, compiler engineers and anyone chasing one-ulp bugs use hexfloats because they eliminate the ambiguity of decimal constants.

  • Pinning exact constants in numeric code. A math library needs a polynomial coefficient reproduced bit for bit on every platform. Convert the value to a hexfloat literal so no compiler's decimal parsing can perturb it.
  • Reading printf %a debug output. You sprinkled %a into logging to capture exact values, and now need to generate matching literals for a regression test. This tool converts the values your test should compare against.
  • Reporting compiler rounding bugs. A bug report about constant folding is far more convincing with hexfloats, since both sides see the exact bits. Convert your inputs and expected outputs before filing the issue.
  • Teaching binary fractions. Showing that 0.375 is exactly 0x1.8p-2 while 0.1 produces an unwieldy repeating mantissa is a memorable demonstration of which decimals binary floating point can represent.

Examples

Twelve

Input

12

Output

0x1.8p+3

Half

Input

0.5

Output

0x1p-1

About the Convert Float to Hexfloat tool

Convert Float to Hexfloat runs as plain JavaScript in your browser tab, with no server behind it. Create a hexfloat number from a floating-point number. Whatever you put in stays on your device from start to finish.

The tool is part of EditSafely's Hex Tools section, 108 single-purpose utilities built around the same idea: open the page, get the result, keep your data to yourself.

You can shape the output with 3 settings, including Precision, Exponent style and Letters, and the result refreshes the moment you change one. 2 worked examples further down the page show exactly what the tool produces for real inputs.

That local-first design has practical benefits beyond privacy. The tool keeps working on a flaky connection once the page has loaded, results are instant because nothing round-trips to a server, and it is safe to use with confidential material.

Frequently asked questions

Is Convert Float to Hexfloat free to use?

Yes, it is completely free. All 2,943 tools on EditSafely work without an account, a subscription or usage limits.

Is it safe to paste sensitive or confidential data?

Everything happens locally. Your browser downloads the tool's code once, then does all the processing itself; nothing you enter is transmitted, stored or logged. You can even go offline after the page loads and it will still work.

How much text can I process at once?

There is no fixed limit; your device's memory is the ceiling. Up to 10 MB the result updates as you type, after a short pause that grows with the size. Above 10 MB a Run button appears so typing stays smooth, and files open up to 50 MB. A very long result shows its first 2,000 lines on screen, while Copy and Download always include all of it.

Do I need to sign up or install anything?

No. The tool works in any modern browser on desktop, tablet or phone. There is no account to create, no extension to add and no software to install.

How do I use the result?

The output panel has a one-click copy button, and you can keep refining the input while you work; the result updates in place as you type.

Related tools

All Hex Tools →