Tutorials › Float32 & Byte Order

A Modbus register is only 16 bits. To carry a 32-bit value - a Float32 (IEEE 754) temperature, a UInt32 counter, an Int32 measurement - a device uses two consecutive registers. The catch is that vendors do not agree on the order of those bytes, which is why a reading that should say 123.45 sometimes shows up as a huge nonsense number.

Two registers, four bytes

Call the four bytes of the 32-bit value A B C D (A is the most significant byte). They are packed into two registers, but the order can be swapped at the word level and at the byte level. The four common combinations are:

OrderRegister 1Register 2Also called
ABCDA BC DBig-endian
DCBAD CB ALittle-endian
BADCB AD CBig-endian, byte swap
CDABC DA BWord swap (common on Siemens)

How to read a Float32 in practice

  1. Read 2 consecutive registers starting at the value's address (for example a holding register read of quantity 2).
  2. Set the display format to Float32 (or Int32 / UInt32 for integers).
  3. If the number looks wrong, change the byte order until it reads correctly - try CDAB and DCBA first, they are the most common culprits.

A quick example

Suppose the value 123.45 (hex 0x42F6E666) is stored as bytes A=42, B=F6, C=E6, D=66. A device using ABCD sends register 1 = 0x42F6 and register 2 = 0xE666. A device using CDAB sends register 1 = 0xE666 and register 2 = 0x42F6. Same value, swapped words - if your tool assumes the wrong order, the float is garbage.

Don't forget scaling

Some devices store a value as a scaled 16-bit integer instead of a float - for example raw 1234 meaning 123.4 °C (scale 0.1). If a "float" still looks off after trying every byte order, check the device manual for a scale factor.

Try it with ModbusBB

ModbusBB lets you switch a register's format to Float32/Int32/UInt32 and cycle byte order (ABCD/DCBA/BADC/CDAB) per register - so you can find the right interpretation in seconds. Its simulator can also serve 32-bit values in any byte order for testing. Download the free trial.

Keep Learning

Next: what Modbus exception codes mean and how to fix them.