extracting highbyte and lowbyte into 16 bit from serial port

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 20
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

extracting highbyte and lowbyte into 16 bit from serial port

Post by tcbcats » Mon Aug 31, 2020 9:12 pm

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.
tcbcats

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3122
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Tue Sep 01, 2020 12:31 am

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)

Post Reply

Return to “Windows”