# Change the byte order in a Modbus 32 bits register

**URL:** <https://forum.inductiveautomation.com/t/change-the-byte-order-in-a-modbus-32-bits-register/12853>\
**Category:** Ignition\
**Created:** [March 28, 2017, 3:03pm UTC](https://forum.inductiveautomation.com/t/change-the-byte-order-in-a-modbus-32-bits-register/12853 "2017-03-28T15:03:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea.minu](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andrea.minu/32/3326_2.png) [@andrea.minu](https://forum.inductiveautomation.com/u/andrea.minu)\
**Post date:** [March 28, 2017, 3:03pm UTC](https://forum.inductiveautomation.com/t/change-the-byte-order-in-a-modbus-32-bits-register/12853/1 "2017-03-28T15:03:27Z")

</div>

Hello

I have to connect to a device using Modbus TCP protocol  
I should to change the Byte order when I read a 32 bit register ( float and long) in according with Intel-formatted data.

The driver can only reverse the word order in a 32 bit register but not the byte order

Has anyone did this with ignition?

Thank you very much

Andrea

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 28, 2017, 4:09pm UTC](https://forum.inductiveautomation.com/t/change-the-byte-order-in-a-modbus-32-bits-register/12853/2 "2017-03-28T16:09:00Z")

</div>

Does the entire byte order need to be reversed?

If so:

[code]import struct

i = 2864434397  
s= struct.unpack("\<I",struct.pack("\>I",i))[0]  
print i, hex(i)  
print s, hex(s)  
[/code]  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b555f4385b814ca325227197e65fb48d39fa8288.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 28, 2017, 5:39pm UTC](https://forum.inductiveautomation.com/t/change-the-byte-order-in-a-modbus-32-bits-register/12853/3 "2017-03-28T17:39:17Z")

</div>

For another technique, you can flip things around using some Java types:

`def int32BE_to_float32LE(i): 
	from java.lang import Float, Integer
	return Float.intBitsToFloat(Integer.reverseBytes(i))`

---

<div class="post-metadata">

**Author:** ![andrea.minu](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andrea.minu/32/3326_2.png) [@andrea.minu](https://forum.inductiveautomation.com/u/andrea.minu)\
**Post date:** [April 2, 2017, 12:31pm UTC](https://forum.inductiveautomation.com/t/change-the-byte-order-in-a-modbus-32-bits-register/12853/4 "2017-04-02T12:31:28Z")

</div>

Hi

Thank you very much to everybody  
…two great solutions!!!

![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:")

Andrea
