Page 1 of 1

extracting highbyte and lowbyte into 16 bit from serial port

Posted: Mon Aug 31, 2020 9:12 pm
by tcbcats
I have 2 bytes from a serial port that represent a 16 bit number. They arrive as highbyte and lowbyte of a 16 bit word.
I need to convert the 2 bytes back into a 16 bit number so I can show it in a text field.
Does anyone have an example on how to get the 2 received bytes back into a 16 bit number?
It looks like the 2 bytes received in Live code are in a binary 8 bit byte.... just need to convert the 2 bytes back into a 16 bit number.

Thanks.

Re: extracting highbyte and lowbyte into 16 bit from serial port

Posted: Tue Sep 01, 2020 12:31 am
by mwieder
Off the top of my head:

use the format command to convert the binary low byte to a numeric value
use the format command to convert the binary high byte to a numeric value

16 bit value = low byte value + (256*high byte value)