IEEE 754 floating-point format
IEEE 754 is the standard that defines how computers store decimal numbers in binary, using three fields: a sign bit, a biased exponent and a fraction (also called the significand or mantissa). The Institute of Electrical and Electronics Engineers (IEEE) published the standard in 1985 and revised it in 2008 and 2019. Nearly every modern processor, programming language and operating system follows it.
A floating-point number in hex is not a whole number written in base 16. The hex digits encode the sign, exponent and fraction fields packed into 32 or 64 bits, and the decimal value comes from a formula that combines all three fields.
| Property | float32 (single) | float64 (double) |
|---|---|---|
| Hex digits | 8 | 16 |
| Total bits | 32 | 64 |
| Sign | 1 bit | 1 bit |
| Exponent | 8 bits | 11 bits |
| Fraction | 23 bits | 52 bits |
| Exponent bias | 127 | 1,023 |
| Decimal precision | about 7 digits | about 15 to 16 digits |
| Largest normal value | ~3.4 × 10³⁸ | ~1.8 × 10³⁰⁸ |
| Smallest normal value | ~1.2 × 10⁻³⁸ | ~2.2 × 10⁻³⁰⁸ |
How to convert hex to float
Write the hex as 32 binary bits, split them into sign, exponent and fraction, subtract the bias from the exponent, and apply the formula (−1)sign × 1.fraction × 2exponent − bias.
- Write each hex digit as 4 binary bits. Eight hex digits give 32 bits, and sixteen give 64.
- Take the first bit as the sign (0 = positive, 1 = negative).
- Take the next 8 bits as the exponent (11 bits for a double).
- Take the remaining 23 bits as the fraction (52 bits for a double).
- Convert the exponent bits to decimal and subtract the bias (127 for float32, 1,023 for float64).
- Build the significand: place a hidden 1 before the fraction bits, giving 1.fraction in binary.
- Compute the value: (−1)sign × 1.fraction × 2exponent − bias.
Example 1: 3F800000 = 1.0
3F800000 in binary: 0 01111111 00000000000000000000000
Sign: 0 → positive
Exponent: 01111111 → 127 − 127 = 0
Fraction: 000...000 → 1.0 (hidden 1, no fraction bits set)
Value = (+1) × 1.0 × 2⁰ = 1.0Example 2: 40490FDB ≈ 3.14159 (π)
40490FDB in binary: 0 10000000 10010010000111111011011
Sign: 0 → positive
Exponent: 10000000 → 128 − 127 = 1
Fraction: 10010010000111111011011 → 1.5707963... (hidden 1 + fraction bits)
Value = (+1) × 1.5707963... × 2¹ = 3.14159265...The stored value is 3.14159274101257…, not exactly π, because 23 fraction bits give only about 7 decimal digits of precision.
Example 3: C0000000 = −2.0
C0000000 in binary: 1 10000000 00000000000000000000000
Sign: 1 → negative
Exponent: 10000000 → 128 − 127 = 1
Fraction: 000...000 → 1.0
Value = (−1) × 1.0 × 2¹ = −2.0The sign bit alone controls whether the number is positive or negative. The exponent and fraction bits of −2.0 and +2.0 (40000000) are identical.
The exponent bias
The exponent field stores the actual exponent plus a fixed offset called the bias, so negative exponents can be represented without a separate sign bit. Float32 uses a bias of 127, and float64 uses 1,023.
A stored exponent of 127 means an actual exponent of 0 (127 − 127). A stored exponent of 100 means −27 (100 − 127). A stored exponent of 200 means 73 (200 − 127).
| Stored exponent (float32) | Actual exponent | Meaning |
|---|---|---|
| 0 | −126 (special) | Zero or subnormal |
| 1 | −126 | Smallest normal exponent |
| 127 | 0 | Significand × 1 |
| 254 | 127 | Largest normal exponent |
| 255 | — (special) | Infinity or NaN |
The stored values 0 and 255 (all zeros and all ones) are reserved for special values, so the usable exponent range is 1 to 254. That gives actual exponents from −126 to +127.
Normal, subnormal, zero, infinity and NaN
IEEE 754 defines five categories of floating-point values, based on the exponent and fraction fields.
Normal numbers have a stored exponent between 1 and 254 (float32) or 1 and 2,046 (float64). The significand has a hidden leading 1, giving a value of 1.fraction × 2exp − bias. Most floating-point values in a program are normal.
Subnormal numbers (also called denormalized numbers) have a stored exponent of 0 and a non-zero fraction. The hidden bit becomes 0 instead of 1, so the significand is 0.fraction × 21 − bias. Subnormals fill the gap between zero and the smallest normal number, which allows gradual underflow instead of a sudden jump to zero.
Zero has an exponent of 0 and a fraction of 0. IEEE 754 defines both +0 (00000000) and −0 (80000000). The two compare as equal in most languages, but −0 preserves the sign of a value that underflowed from the negative side.
Infinity has an exponent of all ones (255 for float32, 2,047 for float64) and a fraction of 0. Positive infinity is 7F800000, and negative infinity is FF800000. Division by zero and overflow produce infinity.
NaN (Not a Number) has an exponent of all ones and a non-zero fraction. Any operation with no meaningful result, such as 0 ÷ 0 or √(−1), returns NaN. NaN does not equal itself: NaN == NaN is false in every IEEE 754 language.
| Hex (float32) | Value | Exponent | Fraction |
|---|---|---|---|
00000000 | +0 | 0 | 0 |
80000000 | −0 | 0 | 0 |
00000001 | 1.4 × 10⁻⁴⁵ | 0 (subnormal) | 1 |
00800000 | 1.175 × 10⁻³⁸ | 1 (smallest normal) | 0 |
7F7FFFFF | 3.403 × 10³⁸ | 254 (largest normal) | all ones |
7F800000 | +Infinity | 255 | 0 |
FF800000 | −Infinity | 255 | 0 |
7FC00000 | NaN | 255 | non-zero |
Why 0.1 is not exact
0.1 has no finite representation in binary, so a float stores the nearest value it can. In binary, 0.1 is the repeating fraction 0.0001100110011…, which continues forever. A float32 rounds it to 23 fraction bits and produces 0x3DCCCCCD (approximately 0.100000001490116). A float64 gets closer with 0x3FB999999999999A (approximately 0.1000000000000000055511151231257827), but the value is still not exactly 0.1.
This rounding affects every number that is not a sum of powers of 2, such as 0.1, 0.2 and 0.3. The sum 0.1 + 0.2 produces 0.30000000000000004 in most languages, not 0.3. Use a tolerance when you compare floating-point numbers, or use a decimal type for exact decimal arithmetic.
Float byte order (endianness)
Byte order determines whether a multi-byte float stores its most significant byte first (big-endian) or last (little-endian). The hex value 40490FDB represents π as a float32, but only when the bytes are in the order 40 49 0F DB.
Big-endian and little-endian
x86 and most ARM processors store floats in little-endian order: the byte at the lowest memory address is the least significant byte. Network protocols and many file formats use big-endian (network byte order). The same float looks different in memory depending on the architecture.
| Order | Byte sequence for 40490FDB |
|---|---|
| Big-endian (network) | 40 49 0F DB |
| Little-endian (x86) | DB 0F 49 40 |
Modbus and mixed byte order
Modbus, a serial protocol used in industrial controllers and sensors, sends 32-bit floats as two 16-bit registers. Some devices swap the order of the two registers but keep the bytes within each register in place. This word-swapped order (often labelled CDAB) turns 40 49 0F DB into 0F DB 40 49. When a float looks wrong after you read it from a Modbus device, try swapping the two register halves.
Common hex float values
Pick a value to see its three fields.
| Hex (float32) | Decimal | Description |
|---|---|---|
00000000 | 0 | Positive zero |
3F800000 | 1.0 | The multiplicative identity |
40000000 | 2.0 | One exponent step above 1.0 |
40490FDB | 3.14159… | π (closest float32) |
3F000000 | 0.5 | 2⁻¹ |
3DCCCCCD | 0.10000000149… | Closest float32 to 0.1 |
3FC00000 | 1.5 | |
42C80000 | 100.0 | |
C0000000 | −2.0 | Negative two |
7F7FFFFF | 3.403 × 10³⁸ | Largest finite float32 (FLT_MAX) |
00800000 | 1.175 × 10⁻³⁸ | Smallest normal float32 (FLT_MIN) |
7F800000 | Infinity | Positive infinity |
FF800000 | −Infinity | Negative infinity |
7FC00000 | NaN | Quiet NaN |
Float to hex (reverse conversion)
To convert a decimal number to its hex float form, reverse the process. Determine the sign. Find the exponent by counting how many times you multiply or divide by 2 to bring the number between 1 and 2. Write the remaining significand as a binary fraction. Then pack the three fields into 32 or 64 bits.
The converter above handles this direction too: type a decimal value in the second field.
Hex to float in programming
Pick a language to see the call and its output for your value. Eight digits read as float32, and sixteen digits read as float64.
Python
Python's struct module packs and unpacks bytes according to IEEE 754. The format '>f' means big-endian float32, and '>d' means big-endian float64.
import struct
hex_str = '40490FDB'
raw = bytes.fromhex(hex_str)
value = struct.unpack('>f', raw)[0]
print(value) # 3.1415927410125732JavaScript
The DataView object reads and writes IEEE 754 floats from an ArrayBuffer.
const hex = '40490FDB';
const buf = new ArrayBuffer(4);
const dv = new DataView(buf);
dv.setUint32(0, parseInt(hex, 16));
console.log(dv.getFloat32(0)); // 3.1415927410125732C
C stores floats in IEEE 754 natively. Copy the bits from an integer into a float with memcpy.
#include <stdio.h>
#include <string.h>
#include <stdint.h>
int main(void) {
uint32_t bits = 0x40490FDB;
float f;
memcpy(&f, &bits, sizeof f);
printf("%f\n", f); // 3.141593
return 0;
}Java
Java provides Float.intBitsToFloat and Double.longBitsToDouble for direct bit-level conversion.
float f = Float.intBitsToFloat(0x40490FDB); // 3.1415927
double d = Double.longBitsToDouble(0x400921FB54442D18L); // 3.141592653589793| Language | Hex to float32 | Hex to float64 |
|---|---|---|
| Python | struct.unpack('>f', bytes.fromhex(h)) | struct.unpack('>d', bytes.fromhex(h)) |
| JavaScript | DataView.getFloat32 | DataView.getFloat64 |
| C / C++ | memcpy from uint32_t to float | memcpy from uint64_t to double |
| Java | Float.intBitsToFloat | Double.longBitsToDouble |
| Go | math.Float32frombits | math.Float64frombits |
| C# | BitConverter.Int32BitsToSingle | BitConverter.Int64BitsToDouble |
Frequently asked questions
What is hex to float conversion?
What is the difference between float32 and float64?
What is a subnormal (denormalized) number?
What does NaN mean in hex float?
NaN == NaN, returns false.Why does 0.1 + 0.2 not equal 0.3?
What is the exponent bias?
Does byte order affect hex float conversion?
Can I convert a hex integer to a float?
Related tools
- Hex to decimal converter: convert hex integers to decimal with digit-by-digit steps.
- Signed hex to decimal: interpret hex as a signed two's complement integer.
- Hex to binary converter: see the full bit pattern of any hex value.
- Little-endian hex to decimal: convert byte-swapped hex values.