naseeam
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...
And for the case that it's not, I added the implementation...