Float to Hex Converter

Float to hex converter: type a decimal number and get its IEEE 754 bytes in hex, single or double precision. 0.1 is 3DCCCCCD as a single and 3FB999999999999A as a double. Choose the byte order and see the rounding error between what you typed and what is stored.

Float to hex
3.14, -0.5, 1e-7, NaN or Infinity
32-bit float · normal
Your input stays in this browser
How the value is stored
Sign0 (positive)
Exponent field01111011 = 123, unbiased -4
Mantissa field10011001100110011001101
Classnormal
Exact stored value0.100000001490116119384765625
Value you typed, as a double0.1000000000000000055511151231257827021181583404541015625
Rounding error1.490e-9

Float to hex: store the sign, the exponent and the mantissa

To convert a floating point number to hex, write it in binary as 1.xxx times a power of two, then pack three fields: the sign bit, the exponent plus a bias, and the digits after the point. For a 32-bit float that is 1, 8 and 23 bits with a bias of 127, and for a 64-bit double it is 1, 11 and 52 bits with a bias of 1023. The 32 bits, read in groups of four, are the hex.

3DCCCCCD as an IEEE 754 32-bit floatSign 0, exponent field 123 (unbiased -4), mantissa 10011001100110011001101. The value is 0.100000001490116119384765625.0sign01111011exponent (8 bits)10011001100110011001101mantissa (23 bits)hex3DCCCCCDvalue+1.100110011001… × 2^-4decimal0.10000000149011612
3DCCCCCD split into its three fields. The stored exponent 123 minus the bias 127 gives -4; the mantissa supplies the digits after the leading 1. The exact value is 0.100000001490116119384765625.

The diagram is 0.1 as a single. Its exponent field is 123, which is -4 after the bias, because 0.1 is 1.6 times 2 to the power of −4. The mantissa holds the 0.6 as a binary fraction. The converter above does these steps and shows the three fields in the table below the result.

Doing it by hand with a number that fits exactly: 0.15625

Choose a number that is a sum of powers of two, and the arithmetic comes out clean. 0.15625 is 5/32, which in binary is 0.00101. Shift the point until one 1 is in front of it: 0.00101 is 1.01 times 2 to the power of −3. The exponent field is −3 + 127 = 124, which is 01111100 in 8 bits. The mantissa is the part after the point, 01, followed by zeros to fill 23 bits. The sign is 0.

Encoding 0.15625 as a single
StepResult
Binary0.00101
Normalized1.01 × 2^−3
Exponent field−3 + 127 = 124 = 01111100
Mantissa field (23 bits)01000000000000000000000
All 32 bits0 01111100 01000000000000000000000
Regrouped in fours0011 1110 0010 0000 0000 0000 0000 0000
Hex3E200000

Regrouping is the step that trips people up: the field boundaries (1, 8, 23) do not line up with the hex digits, so you write all 32 bits in a row and only then cut them into fours. The page on hex to binary shows the lookup for each group.

Why 0.1 ends in CD: repeating fractions are rounded

The number 0.1 in binary is 0.000110011001100110011, repeating the group 0011 forever. A mantissa with 23 bits can hold only part of it, so the encoder keeps the closest 23 bits. The bits after the cut start with 1100, which is more than half, so the last kept bit is rounded up. Before rounding the mantissa would end in …1100 (hex C); after rounding it ends in …1101 (hex D). That is how the pattern 3DCCCCCC turns into 3DCCCCCD.

The stored number is then 0.100000001490116119384765625, a little above one tenth. The 64-bit pattern, 3FB999999999999A, does the same with 52 bits and ends in A instead of 9 for the same reason. The shortcut for recognizing such values is the repeating pattern in the hex: a run of C, 9, 3 or A digits with a rounded last digit is a decimal fraction with no exact binary form.

Rounding error: stored value against the number you typed

The difference between what you typed and what is stored is the rounding error. Singles carry it in the eighth significant digit, doubles in the seventeenth. The table is computed with the same code as the converter, and it shows that the error depends on the number: 0.5 is exact, 0.1 is not, and a larger number such as 100.1 has a larger absolute error even though the relative error is similar.

Single and double precision encodings and the error of the single
TypedSingle (hex)Single stored exactlySingle errorDouble (hex)
0.13DCCCCCD0.1000000014901161193847656251.49e-93FB999999999999A
0.23E4CCCCD0.200000002980232238769531252.98e-93FC999999999999A
0.33E99999A0.3000000119209289550781251.19e-83FD3333333333333
0.53F0000000.5none3FE0000000000000
1.13F8CCCCD1.100000023841857910156252.38e-83FF199999999999A
100.142C83333100.09999847412109375-1.53e-64059066666666666
1e-733D6BF950.000000100000001168609742308035492897033691406251.17e-153E7AD7F29ABCAF48

Because the error is built into the format, comparing floats for equality after arithmetic is unreliable, and the safe habit is to compare with a tolerance or to compare the hex patterns when you need bit-for-bit equality. The exact decimal of a typed number as a double is also shown by the converter, for example 0.1000000000000000055511151231257827021181583404541015625 for 0.1.

Integers as floats: where counting stops

Whole numbers are exact in a float only while they fit in the 24 significant bits of a single (up to 16,777,216) or the 53 of a double (up to 9,007,199,254,740,992). Beyond that, the spacing between neighbours is 2 or more, and some integers are skipped. 16,777,216 is 4B800000, and 16,777,217 maps to the same pattern, 4B800000, because it sits exactly halfway between two singles and rounds to the one with an even mantissa.

This matters when a counter, an identifier or a timestamp is stored as a float. If the value must stay exact, store it as an integer and convert it with decimal to hex instead. Floats are for quantities that are measured or computed, where the last digit is not meant to be exact.

Negative numbers and negative zero

A float stores sign and magnitude. Flipping the top bit negates the number and nothing else changes, so 2.0 is 40000000 and −2.0 is C0000000. That is different from integers, where negatives use two's complement and every bit changes. The top bit is also why the hex of a negative float starts with 8, 9, A, B, C, D, E or F in the first digit.

Zero has a negative form, 80000000, produced by arithmetic such as −1 × 0 and entered here as -0. It compares equal to 0 but keeps its sign, which shows up in a few places such as 1 ÷ −0, and in the sign of a rounded tiny negative value.

Too large and too small: overflow and underflow

A single holds finite values up to 3.4028235e38 (7F7FFFFF). A larger number rounds to infinity, 7F800000, and the converter shows a warning because the number you typed is not what is stored. At the small end, the smallest normal value is 1.17549435e-38; below that the number becomes a subnormal with fewer digits, so 1e-40 is stored as 000116C2 and reads back as about 9.99995e-41. Under about 1.4e-45 everything rounds to zero.

Values at the edges of single precision
TypedStored asRemark
3.4028235e387F7FFFFFlargest finite single
3.5e387F800000overflows to infinity
1.17549435e-3800800000smallest normal single
1e-40000116C2subnormal, reduced precision
1e-4500000001smallest subnormal single
1e-4600000000underflows to zero

Doubles reach 1.7976931348623157e308 and down to 5e-324, so most values that overflow a single are ordinary doubles. Switch the precision to 64-bit before assuming the number is out of range.

Single or double: which precision to write

Write the precision the reader expects, since the two patterns are different lengths and not interchangeable. Single precision is common in graphics, audio, sensor firmware and file formats that favour compact storage. Double precision is what JavaScript numbers and Python floats are, and what most scientific code and spreadsheets use. If you control the format, a double avoids the visible seventh-digit error and costs four extra bytes.

Byte order when you write the bytes out

The hex shown by default is the number written from the most significant byte, which is how a reference would print it. A file or a memory image on a PC stores the same number little-endian, so 3.14159274 is DB 0F 49 40 when written to memory and 40 49 0F DB when sent in network order. Tick Little-endian bytes to get the memory order, and check which one the receiving format requires; a binary file specification states it for each field.

The same floats in both byte orders
NumberBig-endianLittle-endian
1.53F C0 00 0000 00 C0 3F
3.1415927440 49 0F DBDB 0F 49 40
-2C0 00 00 0000 00 00 C0

Splitting a float into two 16-bit registers

Some device protocols, notably Modbus, carry a 32-bit float in two 16-bit registers. Encode the value, then cut the eight hex digits into two groups of four. For 123.45 the single is 42F6E666, which gives the registers 42F6 and E666. Which register holds the high half is a device convention, so use the byte and word order from the device manual and test with a known value before writing to a production system.

NaN, infinity and negative zero as hex

The converter accepts the words NaN and Infinity, and a minus sign for the negative forms. The results are fixed patterns with the exponent field set to all ones.

Special values as single and double precision hex
TypedSingleDouble
Infinity7F8000007FF0000000000000
-InfinityFF800000FFF0000000000000
NaN7FC000007FF8000000000000
-0800000008000000000000000

The NaN produced here is the quiet NaN that the language runtime creates. Other NaN patterns exist, with a different mantissa, and most programs treat them all alike. If you need an exact NaN payload, write the hex directly and decode it with hex to float.

Float to hex in JavaScript and PowerShell

In JavaScript, a DataView writes a number as a float and reads the bytes back as an integer. In PowerShell, BitConverter returns the bytes in the machine's order, little-endian on Windows. The first line below prints 3DCCCCCD for 0.1; see DataView on MDN.

JavaScript
const view = new DataView(new ArrayBuffer(4));
view.setFloat32(0, 0.1);
console.log(view.getUint32(0).toString(16).toUpperCase()); // 3DCCCCCD

const d = new DataView(new ArrayBuffer(8));
d.setFloat64(0, 0.1);
console.log(d.getBigUint64(0).toString(16).toUpperCase()); // 3FB999999999999A
PowerShell
[BitConverter]::GetBytes([single]0.1) | ForEach-Object { $_.ToString('X2') }   # CD CC CC 3D (memory order)
[BitConverter]::ToString([BitConverter]::GetBytes([double]0.1))               # 9A-99-99-99-99-99-B9-3F

Checking a result by decoding it again

A reliable test of any encoding is to decode it and compare. Paste the hex into hex to float with the same precision and byte order, and the value should come back as the shortest decimal that matches what you typed, for example 0.1 from 3DCCCCCD. If the decoded text differs in the seventh digit for a single, that is normal rounding. If it differs in the first digit, the byte order or the width is wrong.

What you can type, and what the converter rejects

Plain decimals (3.14, -0.5), exponent notation (1e-7, 6.02E23), a leading or trailing dot, and underscores as digit separators (1_000.5) are read as numbers. A comma is treated as the decimal point, so 1,5 is 1.5 and a thousands separator is not supported; write 1000.5, not 1,000.5. Words other than NaN and Infinity, hex input, units and more than one decimal point are rejected with a message instead of being guessed.

Only the 32-bit and 64-bit formats are offered, because those are the ones programming languages and file formats store natively. Half precision (16 bits) and the 80-bit or 128-bit extended formats have other field sizes and are not produced here. When a source does not say which width it uses, the length of its hex tells you: 8 digits for a single and 16 for a double.

Questions about converting a float to hex

What is 1.0 as a float in hex?

3F800000 in single precision and 3FF0000000000000 in double precision. Both have a zero mantissa; only the exponent field differs, 127 in one and 1023 in the other.

Why does 0.1 end in CD in single precision?

Because 0.1 is a repeating fraction in binary, so the 23-bit mantissa is rounded, and the rounding pushes the last hex digits from CC to CD. The stored value is 0.100000001490116119384765625, slightly above 0.1.

Is a negative float the two's complement of the positive one?

No. A float is sign and magnitude: only the top bit changes. 2.0 is 40000000 and -2.0 is C0000000. Two's complement applies to integers, as on the decimal to hex page.

What happens if my number does not fit in 32 bits?

Above about 3.4028235e38 it is stored as infinity, 7F800000, and the converter warns you. Below about 1.4e-45 it becomes zero. Between 1.17549435e-38 and 1.4e-45 it is stored as a subnormal with fewer significant digits.

Which byte order should I use?

Use the one the receiving system reads. Memory on a PC and most files from it are little-endian, so 3.14159274 is DB 0F 49 40. Network protocols commonly send big-endian, 40 49 0F DB. When in doubt, check the specification of the format.