Modbus float32 word order converter
Enter the two 16-bit registers and the page shows the IEEE 754 float32 value under all four byte orders, with the int32 and uint32 readings beside it; the order that gives a believable number is the one your device uses. You can also enter a float and get the register pair for each order.
Calculator
This calculator needs JavaScript. Without it, use the formulas under "How it works" and the worked example.
Two registers to float32
Each register as decimal (0 to 65535) or hex with a 0x prefix. The first register is the one at the lower address in the read request. The expected range marks the orders whose value falls inside it.
Float to two registers
A decimal number such as -0.5 or 1.2e3, or the words nan, inf or -inf. The value is rounded to the nearest float32 first.
How it works
Modbus sends every register as two bytes, high byte first. It does not say how a 32-bit number is split across two registers, so devices differ. Call the four bytes of the number A, B, C, D, with A the most significant. The four orders put them in the two registers like this, where the first register is the one at the lower address:
| Order | First register holds | Second register holds |
|---|---|---|
| ABCD | A B | C D |
| CDAB | C D | A B |
| BADC | B A | D C |
| DCBA | D C | B A |
The calculator rebuilds the 32 bits A B C D for each order and reads them as an IEEE 754 single-precision number. With sign bit s (bit 31), exponent field e (bits 30 to 23) and fraction field m (bits 22 to 0):
value = (-1)^s × 2^(e - 127) × (1 + m / 2^23) for 0 < e < 255 value = (-1)^s × 2^(-126) × (m / 2^23) for e = 0 (zero or subnormal) e = 255: infinity when m = 0, otherwise NaN
The int32 column reads the same 32 bits as a two's-complement signed integer and the uint32 column as an unsigned integer. A negative decimal from -32768 to -1 is taken as the signed form of the same 16 bits.
The Plausible column is a rule of thumb, not a proof: it says Yes when the value is finite and is either zero or between 0.0001 and 10,000,000 in size. If you type an expected minimum and maximum, it says Yes when the value lies inside them. To go the other way, the float is rounded to float32, split into A B C D and placed in the two registers according to the table above.
Worked example
A device returns the registers 0x42F6 and 0xE979 (decimal 17142 and 59769). Read as ABCD the four bytes are 42 F6 E9 79, which is 0x42F6E979.
- Sign bit s = 0.
- Exponent field e = 0x85 = 133, so the power of two is 133 - 127 = 6.
- Fraction field m = 0x76E979 = 7793017, so 1 + 7793017 / 8388608 = 1.929000020.
- value = 2^6 × 1.929000020 = 123.456 (the nearest float32 to 123.456 is stored as 123.45600128173828).
The same two registers read in the other orders give -1.8833671e+25 (CDAB), -9.8611155e+32 (BADC) and 1.5184998e+35 (DCBA). Only ABCD gives a value that looks like a measurement, so ABCD is the order this device uses. Going back, 123.456 gives 0x42F6 then 0xE979 in ABCD and 0xE979 then 0x42F6 in CDAB.
Common mistakes
- Modbus fixes the byte order inside one register (high byte first) but not the order of the two registers in a 32-bit value. The device manual, or a test with a known value, decides it.
- The names are not standard. "Word swap", "little-endian" and "mid-endian" mean different layouts in different tools. Go by the byte pattern in the table, not by the label.
- Test with a value you know. 1.0 is 0x3F800000, so ABCD gives the registers 0x3F80 and 0x0000, and CDAB gives 0x0000 and 0x3F80.
- Start at the wrong address, or read the two registers in separate requests, and you get half of one value with half of the next one. That looks like a word-order fault but is an addressing fault.
- A float32 holds about seven significant decimal digits. A whole-number count kept in a float32 is no longer exact above 16,777,216, so use an integer type for counters.
Related articles
- Why a Modbus 32-bit float reads wrong after a CPW copy
- Scaling Modbus floating point values to 4-20 mA outputs
- Why AdvancedHMI Modbus TCP floats stop reading a PLC
- Reading a CLICK PLC float over Modbus TCP in an HMI
- How an S7-1200 reads PAC3200 floats over Modbus RTU
- Why a BRX PLC needs an even first word to read a Modbus Float32
- Modbus holding register vs input register: which one to use
- What CODESYS %IW0 means for a Modbus TCP holding register