Internet PLC Forum
General => Technical support => Topic started by: pixelfantastic on May 16, 2011, 11:18:41 AM
-
Hi guys,
can anyone please help?
I have a 4 bytes INT32 coming in via rs232, and the byte order is lowbyte first
(LSB -- low, high, low,high -- MSB)
how can i convert this to signed integer ?
result should be from -2147483648 to +2147483647
Thanks for your assistance
Barrie
-
Since the data come in through RS232 port, are you able to read them into DM[] area using INCOMM command?
If so then each byte would have been stored DM and you can then rearrange the DM to convert into 32-bit number.
E.g. if the data are stored in DM[1] to DM[4], you can covert into 32-bit integer as follow:
DM[5] = DM[4]*256+DM[3]
SETHIGH16 A, DM[5]
A = A + DM[2]*256+DM[1]
A will contain the signed 32-bit numbers that is converted from DM[1] to DM[4], with DM[4] being the most significant byte.
-
Thanks for that!
i worked perfectly
Barrie