Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

How to swap bytes ?

I read a word from modbus register.  I need to swap the bytes:

i.e.  I read   0x0003

I need to swap them so result would be     0x0300

Please provide a software instructions to achieve this.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that ntohs would only work if the host byte order is different from the network byte order (ie. the host byte order is little endian) - otherwise it's a noop.
I was not too unsure in assuming that the host platform was Intel ;o)

And for the case that it's not, I added the implementation...