Thanks guys,
The routine below is supposed to take comma-delimited strings and convert them to binary. It should handle the sequence 02,A,A2 for example, properly.
Code:Preparser: HSERIN [Wait (":")] ; wait for colon to start GrabAscii: HSERIN 500,NoMoreInput,[ASCIN [Y]] ; Load it into small array, first char goes into element zero IF ASCIN [Y] = "," THEN ; Found a comma This will never be in element zero , but ; may exist in element 1 SELECT CASE Y CASE 1 MSB = 0 LSB = ASCIN[Y-1] CASE 2 MSB = ASCIN[Y-2] LSB = ASCIN[Y-1] CASE ELSE HSEROUT ["INPUT ERROR"] PAUSE 2500 END SELECT GOSUB IHEX2BIN OUTARRAY[Z] = ByteVal ; load variable into array Z = Z + 1 Y = 0 ; Clear Y if we found a comma ENDIF Y = Y + 1 Goto GrabAscii NOMoreInput: ...... ';************************************************************** '; Routine takes HEX Ascii chars '; and converts to BIN '; Inputs MSB, LSB ("0" to "F") '; Outputs ByteVal ';*************************************************************** IHEX2BIN: LOOKDOWN MSB,["0123456789ABCDEF"],ByteValH LOOKDOWN LSB,["0123456789ABCDEF"],ByteValL ByteVal = (ByteValH << 4) + ByteValL RETURN ';***************************************************************
It is nearly 4 A.M here in CA. Time to go to work and see how the code works!




Bookmarks