Modbus DISCUSSION

Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

Started by rajah Modbus floatword orderbyte swapIEEE 75432-bit register pair
5 replies 248 views 6 participants
Latest activity · 30 Sep 2026

Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

rajah Modbus Forum
#1

A power meter stores line voltage as a 32-bit float in holding registers 100 and 101. I read the two registers and get 0x8000 and 0x4366. Combining them as (first << 16) | second and converting to float gives a tiny number around -2.4e-41 instead of roughly 230 V.

The manual only says "float, 2 registers". How do I know the correct order, and is there a standard for this in Modbus?

Community replies 5

Re: Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

#2

Modbus defines only 16-bit registers, each sent high byte first. It says nothing about how a 32-bit value is split across two registers, so manufacturers chose both ways. With the four bytes of the float named A B C D from most to least significant, the two common layouts are ABCD (high word in the first register) and CDAB (low word first, often called word-swapped).

Your registers 0x8000 and 0x4366 are the CDAB case. Put the second register in the high half: 0x43668000, which is 230.5 as an IEEE 754 single-precision float.

Re: Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

#3

You can confirm the decoding by hand. 0x43668000 has sign bit 0, exponent bits 1000 0110 = 134, and a fraction field of 0x668000. The value is (1 + 0x668000 / 0x800000) × 2^(134 - 127) = 1.80078 × 128 = 230.5.

When the order is wrong, the exponent field comes from the wrong bytes, which is why the result is absurdly small or huge rather than slightly off. That is a useful signature: a plausible-looking but wrong number usually means a scaling issue, an absurd one means a word or byte order issue.

Re: Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

#4

Two rarer layouts exist in which the bytes inside each register are also swapped: BADC and DCBA. Most libraries and SCADA drivers expose all four as a setting with names such as "byte swap" and "word swap". In Python you can do it without library helpers: struct.unpack('>f', struct.pack('>HH', reg[1], reg[0]))[0] for the word-swapped case, with reg[0], reg[1] for ABCD.

If the manual is silent, read a quantity whose value you know from the device display and try the four combinations; only one gives the displayed number.

Re: Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

#5

Read both registers in one request. If you read register 100 and register 101 in two separate transactions, the device may update the value in between, and you combine the high word of one sample with the low word of the next. Within a single read request a well-behaved device returns a consistent pair.

The same ordering question applies to 32-bit integers. Energy counters are often UINT32, or 64-bit across four registers, so note the word order per device in your tag list rather than assuming it is the same across brands.

Re: Reading a 32-bit float from two Modbus registers gives a nonsense value: which word order?

#6

Also check whether the value is a float at all. Many meters and drives send scaled integers instead: a register value of 2305 with a documented scale of 0.1 means 230.5 V, and signed quantities use two's complement INT16, so 0xFFF6 is -10, not 65526.

If the manual has a "multiplier" or "resolution" column, the value is almost certainly a scaled integer, and treating two registers as a float will again produce nonsense.

TEP COMMUNITY