IEEE 754 float converter

Convert a decimal number to its IEEE 754 32-bit or 64-bit hex, or hex back to a number, with the Modbus register words in every byte order.

Have a number to send? Convert it here. To decode the registers a device returns, use the Modbus register decoder.

Modbus and serial Updated Free, no sign-up

Example values
What do you want to convert?
Conversion
Precision
Value

Such as 230.5, -12 or 1.5e-3

Eight digits for 32-bit, sixteen for 64-bit; spaces allowed

32-bit single precision in hex

0x43668000

32-bit single precision.

Value actually stored
230.5
Sign bit
0 (positive)
Exponent
134 − 127 = 7
Fraction, 23 bits
0x668000
Class
Normal number
Modbus registers, ABCD (big-endian)
4366 8000
Modbus registers, CDAB (word swap)
8000 4366
Modbus registers, BADC (byte swap)
6643 0080
Modbus registers, DCBA (little-endian)
0080 6643
How it’s calculated
  1. x = (−1)s × 1.f × 2e − 127=(−1)⁰ × 1.80078125 × 2⁷=230.5

230.5 as an IEEE 754 32-bit single precision float is 0x43668000.

Tip: If a meter reads a sensible number in one word order and nonsense in the others, that order is the device’s. Registers 4120 0000 read 10 in ABCD order and 2.3e-41 in CDAB.

How to convert a float to hex and back

An IEEE 754 single-precision float stores a number in 32 bits: 1 sign bit, 8 exponent bits and 23 fraction bits. 230.5 is stored as 0x43668000. Energy meters, power analysers and PLCs use this format for readings such as voltage, power and frequency, and send it over Modbus as two 16-bit registers.

The register values a device returns are the raw bits. Reading them as integers gives nonsense, so the bits have to be decoded as a float, in the right word order.

The value of a stored float

x = (−1)s × 1.f × 2e − 127

s is the sign bit, e the 8-bit exponent field and f the 23 fraction bits read as a binary fraction. The leading 1 is implied, so it is not stored. For 64-bit doubles the exponent has 11 bits and a bias of 1023, and the fraction has 52 bits.

Decimal to hex

Find e and f so that 1.f × 2e − 127 is the nearest value to x

Most decimals have no exact binary form, so the float stores the nearest one. 0.1 becomes 0.100000001490116, stored as 0x3DCCCCCD. The calculator shows the value actually stored and the rounding error.

Special values

e = 0: zero or subnormal; e = 255: infinity or NaN

An exponent field of all zeros holds zero and the subnormal numbers below 1.18 × 10−38. All ones holds infinity (fraction zero) or NaN, “not a number”. Many meters send NaN, often 0x7FC00000, for a reading they cannot make.

Modbus defines only 16-bit registers, sent high byte first, so a 32-bit float takes two. The standard says nothing about which register comes first. Many devices send the high word first (ABCD), many others the low word first (CDAB), and a few swap the bytes inside each register as well (BADC, DCBA). The device’s register map should say; when it does not, the order that gives a plausible reading is the right one.

IEEE 754 float examples

A frequency of 50 Hz

50 is 1.5625 × 25, so the sign bit is 0, the exponent field is 5 + 127 = 132 and the fraction holds 0.5625. The result is 0x42480000, sent over Modbus as the registers 4248 0000 in ABCD order.

32-bit single precision in hex 0x42480000 Open in the calculator

The same registers in the wrong order

If a meter sends the low word first and the software reads it high word first, 50 Hz arrives as 0000 4248. Read as ABCD that is 2.3777e‑41, a subnormal number close to zero. A reading that is tiny, huge or NaN where a normal value belongs is the usual sign of a word-order mismatch.

Decimal value 2.3777e-41 Open in the calculator

Why 0.1 is not exactly 0.1

In binary, 0.1 repeats for ever, like 1/3 in decimal. The nearest 32-bit float is 0.100000001490116, stored as 0x3DCCCCCD. The error is about 1.5 × 10−9, far below any meter’s accuracy, but it is why a float compared with 0.1 for exact equality can fail.

32-bit single precision in hex 0x3DCCCCCD Open in the calculator

Float to hex table for common values

The IEEE 754 bit patterns of values that turn up in meter registers, in ABCD order.

Decimal32-bit64-bit
00x000000000x0000000000000000
10x3F8000000x3FF0000000000000
−10xBF8000000xBFF0000000000000
0.50x3F0000000x3FE0000000000000
0.10x3DCCCCCD0x3FB999999999999A
20x400000000x4000000000000000
100x412000000x4024000000000000
500x424800000x4049000000000000
600x427000000x404E000000000000
1000x42C800000x4059000000000000
2300x436600000x406CC00000000000
4000x43C800000x4079000000000000
10000x447A00000x408F400000000000
3.141590x40490FD00x400921F9F01B866E

Download this table (CSV)

Questions about IEEE 754 floats

How many digits does a 32-bit float hold?

About 7 significant decimal digits. Above 16,777,216 (224) not every whole number can be stored, which matters for energy counters: a kWh total held as a 32-bit float stops counting in single units once it passes about 16.8 million. Meters that keep large totals use 64-bit floats or integers for this reason.

What are ABCD, CDAB, BADC and DCBA?

The four byte orders a device can use for a 32-bit value in two registers. A is the most significant byte. ABCD sends the high register first with big-endian bytes, as Modbus does for single registers. CDAB swaps the two registers; BADC swaps the bytes in each register; DCBA does both.

Is the hex the same as what the meter sends?

In ABCD order, yes: the hex is the four bytes in the order they appear on the wire. For other orders, use the register words the calculator lists for that order. The Modbus register decoder starts from the registers and shows every order at once.

Why does a meter report NaN?

NaN means the value is not available: a phase with no voltage, a power factor at zero current, or a register the device does not implement. Treat it as a missing reading rather than zero.

Limits of this result

  • Modbus defines 16-bit registers only. How a device packs a float into registers is set by its own register map, not by the protocol.
  • A NaN has many bit patterns; this tool shows the one entered or the platform’s default.
  • Decimal input is read as a 64-bit number first, so digits beyond about 17 significant figures are ignored.

Read Modbus devices on the Gateway

Edge reads Modbus meters over TCP and RTU and decodes each register by the type and word order in its device template. A ZMB connects an RS-485 meter to the Gateway wirelessly.

Related guides

Sources

  1. IEEE Standard for Floating-Point Arithmetic (IEEE 754-2019) (opens in a new tab) IEEE, 2019-07-22
  2. MODBUS Application Protocol Specification (opens in a new tab) (PDF) Modbus Organization, V1.1b3, 2012-04-26