How do I convert hex strings to decimal in smartBASIC?

If your data is arriving in the form of a hex string, you first need a routine to extract the characters you wish to convert to decimal. In this example, we will be converting 6 bits that arrive in a string from hex to decimal. These bits will be characters 57-62 in our 56 byte data package. For that, we'll need: StrSubCommand$ = MID$(StrCommand$, 57, 6) You then need to reverse the string, there is no function that does this in smartBASIC, but you can do this programmatically using a FOR loop, a pseudocode example would be as follows:  StrReversedSubCommand$ = "" FOR i=STRLEN(StrSubCommand$) DOWNTO 1     StrReversedSubCommand$ = StrReversedSubCommand$ + MID$(StrSubCommand$, i, 1) NEXT  We then want to convert this string hex into a decimal (i.e. from "0004D2" to "1234"), and for that we'll need a some code and the use of the StrHex2Bin smartBASIC function as follows:-  DecimalValue = StrHex2Bin$(StrReversedSubCommand$, 0)*65536 + StrHex2Bin$(StrReversedSubCommand$, 2)*256 + StrHex2Bin$(StrReversedSubCommand$, 4)

Products