Modbus Word to Float Conversion (Big-Endian Byte Swap)

When transferring floating-point values via Modbus TCP/IP, devices often split a 32-bit floating-point number into two 16-bit Modbus registers.

However, many industrial devices send the bytes in a different order than the receiving PLC expects. This is why we often need to apply a Big-Endian Byte Swap before converting the registers to a floating-point value.

This guide explains:

  • Why byte swapping is needed

  • What Big-Endian Byte Swap (BADC) means

  • How to convert registers into a REAL / float

  • Multiple real industrial examples

1. Why Byte Swapping is Needed in Modbus

The Modbus protocol was originally designed to transfer 16-bit register values.

A register contains:

16 bits = 2 bytes

But a floating-point number requires:

32 bits = 4 bytes

So a device must split the float across two registers.

Example float:

0.1251

IEEE-754 representation:

Split into bytes:

Stored in Modbus registers

This layout is called:


2. The Industry Problem

The Modbus specification does not define how 32-bit values should be arranged across registers. Different vendors, therefore, implemented different byte orders.

Common layouts used in industry:

Layout
Byte Order
Description

ABCD

Big Endian

Standard order

CDAB

Word Swap

Registers swapped

BADC

Byte Swap

Bytes swapped within registers

DCBA

Full Reverse

Completely reversed

Because of this, PLCs often must rearrange the bytes before converting to a float.


3. What Big-Endian Byte Swap Means

Big-Endian Byte Swap rearranges the bytes from:

to:

This means:

  • swap bytes inside each register

  • keep register order the same

Visual representation:


4. Example - Real Industrial Data

Modbus registers from a vibration sensor:

Convert to HEX:

Bytes:

Apply Byte Swap (BADC):

Combine into 32-bit value:

Convert to float:


5. How PLCs Perform This Conversion

Typical steps used in PLC or C/C++ code:

Step 1 - Extract bytes

Step 2 - Rearrange bytes

Step 3 - Combine into a 32-bit value

Step 4 - Interpret as float

6. Why Industry Uses Byte Swapping

Byte swapping is common in industrial automation because devices may have:

Different CPU architectures

Examples:

  • ARM processors

  • Intel processors

  • DSP controllers

  • Embedded microcontrollers

Each architecture may represent multi-byte values differently.


Legacy Modbus implementations

Many industrial devices were designed decades ago, when memory layout decisions differed between manufacturers.

Therefore:

PLCs must adapt to the device format.


Sensor manufacturers

Common devices requiring byte swapping:

  • Vibration sensors

  • Power meters

  • Drives

  • Temperature transmitters

  • PLC-to-PLC communication

  • SCADA systems


9. How Engineers Detect the Correct Byte Order

A common debugging trick:

  1. Read the two registers

  2. Try all four byte layouts

  3. See which one produces a realistic value

Example:

Expected vibration value:

Possible interpretations:

Correct format is clearly:


10. Summary

Key points:

  • Modbus registers are 16-bit

  • Floats require 32-bit

  • Devices split floats across two registers

  • Modbus does not define 32-bit ordering

  • Different vendors use different layouts

  • Big-Endian Byte Swap (BADC) rearranges bytes from:

This ensures the PLC reconstructs the correct IEEE-754 floating-point value.


11. Practical Tip

Whenever a Modbus float looks incorrect:

In many industrial sensors, the correct format is:

circle-info

Last updated