Float to Hexfloat Converter

Converts a decimal floating-point number into C99/printf "%a" hexfloat notation (a hex mantissa times a power of two, like 0x1.8p+3), by reading the value's exact IEEE-754 double bits, the direct inverse of the Hexfloat to Float Converter. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

Overview

Introduction

Decimal representations of floating-point numbers are often rounded for readability, which can hide exactly what value is actually stored in memory.

This tool sidesteps that by reading a float's raw IEEE-754 bits directly and expressing them as exact C99 hexfloat notation.

What Is Float to Hexfloat Converter?

A converter that encodes a decimal floating-point number as C99/printf "%a" hexfloat notation, an exact hex mantissa multiplied by a power of two.

It's the direct inverse of Hexfloat to Float Converter, and distinct from Floating Point Number to Hex Converter, which outputs the value's raw IEEE-754 bit pattern as a plain hex string rather than this dot-and-exponent notation.

How Float to Hexfloat Converter Works

The input value is written into an 8-byte buffer as a double-precision float, then its sign, 11-bit exponent, and 52-bit mantissa are read directly from the raw bits via DataView, avoiding any decimal-based rounding.

The mantissa's 52 bits become 13 hex digits (with an implicit leading 1 for normal numbers), trailing zero hex digits are stripped, and the biased exponent is converted to its true (unbiased) power-of-two value before being formatted as "0x{digit}.{fraction}p{sign}{exponent}".

When To Use Float to Hexfloat Converter

Use it to see the exact hexfloat form of a decimal value, matching what printf("%a", ...) in C/C++ or Python's float.hex() would print.

It's useful for constructing precise hexfloat literals for C99 source code or test fixtures, and for debugging subtle floating-point precision differences.

Features

Advantages

  • Exact by construction, since it reads the value's true IEEE-754 bits rather than deriving hex digits from decimal digits.
  • Produces a canonical, minimal form by stripping trailing zero mantissa digits.
  • Handles the zero, negative-zero, and subnormal edge cases explicitly.

Limitations

  • Infinity and NaN are rejected, since they have no standard finite hexfloat representation.
  • Only encodes double (64-bit) precision; there's no option to instead express the value at float32 (single) precision.

Examples

Encoding a small integer value

Input

12

Output

0x1.8p+3

12 = 1.5 × 2^3; the mantissa 1.5 is 1 + 8/16 in hex, giving "1.8".

Encoding exactly 1

Input

1

Output

0x1p+0

1 = 1.0 × 2^0; since the fractional mantissa bits are all zero, no fraction is shown.

Best Practices & Notes

Best Practices

  • Round-trip the output through Hexfloat to Float Converter if you want to double check the encoding matches your expectation.
  • Remember the mantissa digits after the dot are hexadecimal (base 16) fractions, not decimal ones, "0x1.8" means 1.5, not 1.8.

Developer Notes

Implemented with `DataView.prototype.setFloat64`/`getUint32` to extract the sign, biased 11-bit exponent, and 52-bit mantissa as exact integers, then `mantissaHex.replace(/0+$/, "")` trims trailing zero hex digits before assembling the final string; verified by hand that 12 → "0x1.8p+3" and 1 → "0x1p+0", and that both round-trip exactly back through Hexfloat to Float Converter.

Float to Hexfloat Converter Use Cases

  • Writing an exact C99 hexfloat literal for source code or test data
  • Comparing a value's true stored bits against its rounded decimal display
  • Reproducing the output of printf("%a", ...) or Python's float.hex() for a given value

Common Mistakes

  • Reading the mantissa's fractional digits as decimal instead of hexadecimal, ".8" means 8/16 = 0.5, not 0.8.
  • Expecting Infinity or NaN to produce hexfloat output; both are rejected since they have no finite hex-mantissa form.

Tips

  • Use Floating Point Number to Hex Converter instead if you want the value's raw IEEE-754 bits as a plain hex string rather than this dot-and-exponent notation.
  • A trailing fraction of a single hex digit (like ".8" or ".4") usually means the value is a simple multiple of a power of two, like 1.5 or 1.25.

References

Frequently Asked Questions