Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Hex to Short (16-bit signed)


kevnoto Jun 8, 2017 06:58 PM

I'm using a CR6 to communicate to a device via TTL and parse the incoming string. The string is parsed into hex values, and this is where my problem starts; The only function I could find built into the CRBasic was HexToDec, which converted the string to an unsigned 32-bit Long. Is there an easy way for me to convert the Hex to signed 16-bit Short?


JDavis Jun 8, 2017 09:05 PM

Get it into a 32 bit Long, then handle the sign.

 Here is a simple Function you can use to handle the sign on a 16 bit integer:

Function SignedInt16(tempDec As Long) 'Converts two byte long to 16bit signed
  If tempDec>32767 Then
    tempDec=tempDec-65536
  EndIf
  SignedInt16=tempDec
EndFunction

 

Log in or register to post/reply in the forum.