Hexfloat to Float Converter

Parses C99/printf "%a" hexadecimal floating-point notation (a hex mantissa times a power of two, like 0x1.8p3) into the exact decimal number it represents, useful for reading values printed by C, C++, Java, or Python's float.hex(). A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

Overview

Introduction

C99 introduced hexfloat notation specifically so a floating-point value's exact bits could be written and read back without any decimal rounding ambiguity.

This tool parses that notation, like "0x1.8p3", back into the plain decimal number it represents.

What Is Hexfloat to Float Converter?

A parser for C99/printf "%a" hexadecimal floating-point notation: a hex mantissa (an integer part, optionally a fractional part after a dot) multiplied by 2 raised to a decimal exponent given after a mandatory "p".

It's distinct from Hex to Floating Point Number Converter, which decodes a raw IEEE-754 bit pattern hex string; this tool instead parses the human-readable %a notation format, which encodes the same kind of value in a completely different textual layout.

How Hexfloat to Float Converter Works

The input is matched against a pattern requiring an optional sign, a "0x" prefix, hex mantissa digits (integer part and/or fractional part after a dot), and a mandatory "p" followed by a signed decimal exponent.

The mantissa's integer and fractional hex digits are combined into one integer and divided by 16 raised to the fractional digit count, then multiplied by 2 raised to the parsed exponent, and the original sign is reapplied.

When To Use Hexfloat to Float Converter

Use it to read a value printed by C/C++'s printf("%a", ...), Python's float.hex(), or a debugger that shows floats in this exact hex-and-power-of-two format.

It's also useful for understanding exactly what a given hexfloat literal (sometimes used directly in C99 source code) actually evaluates to.

Features

Advantages

  • Parses the mantissa as a single combined integer divided by a power of 16, keeping the conversion exact for typical double-precision mantissas.
  • Accepts both upper and lowercase notation, and an optional sign on both the value and the exponent.
  • Handles mantissas with only an integer part, only a fractional part, or both.

Limitations

  • Extremely long mantissas (well beyond the 13 hex digits a standard double's 52-bit mantissa produces) may lose a little precision in the intermediate integer parse, though this doesn't affect any value actually produced by Float to Hexfloat Converter.
  • Does not accept the literal "inf" or "nan" tokens some printf implementations also allow after %a; only the numeric hex-mantissa form is supported.

Examples

A textbook hexfloat example

Input

0x1.8p3

Output

12

Mantissa 1.8 in hex is 1 + 8/16 = 1.5; multiplied by 2^3 (=8) gives 12.

A hexfloat with no fractional part

Input

0x1p0

Output

1

Mantissa 1 with no fraction, multiplied by 2^0 (=1), is simply 1.

Best Practices & Notes

Best Practices

  • Make sure the exponent's "p" is present, it's what distinguishes valid hexfloat notation from an incomplete or malformed value.
  • If you're not sure whether you have %a notation or a raw IEEE-754 hex bit pattern, look for the dot-and-p structure (%a) versus a plain run of 8 or 16 hex digits (raw bits, use Hex to Floating Point Number Converter instead).

Developer Notes

Parsing uses the regex `/^([+-]?)0x([0-9a-f]*)(?:\.([0-9a-f]*))?p([+-]?\d+)$/i`, then combines the integer and fractional hex digit groups into one integer via `parseInt(combined, 16)` divided by `16 ** fractionLength` before applying `Math.pow(2, exponent)`; this was verified to round-trip exactly against Float to Hexfloat Converter's output for values like 12 and 1.

Hexfloat to Float Converter Use Cases

  • Reading a value printed by printf("%a", ...) or Python's float.hex()
  • Understanding a C99 hexfloat literal found in source code
  • Cross-checking a manual hexfloat calculation

Common Mistakes

  • Omitting the "p" exponent, thinking a plain "0x1.8" is valid hexfloat notation on its own; C99 requires the exponent even when it's zero ("p0").
  • Confusing this notation with the raw IEEE-754 bit-pattern hex handled by Hex to Floating Point Number Converter, they look similar but follow completely different rules.

Tips

  • Use Float to Hexfloat Converter to go the other direction and see the canonical hexfloat form of any decimal value.
  • A mantissa fraction like ".8" in hex is 8/16 = 0.5, not 0.8, remember the hex digits are base-16 fractional places, not decimal ones.

References

Frequently Asked Questions