I know my questions must seem random. I'm still in the infancy stages of programming, and play with different products in my spare time. I picked up a Parallax RFID reader as we work with RFID quite a bit in my line of work (automation). I have previously taken this technology for granted and just interfaced (expensive) off-the-shelf devices to a PC or PLC.
To the issue at hand... The parallax RFID reader returns 10 alphanumeric hex digits in to a string array. Obviously a 10 digit hex value is too large for a LONG variable, so I have broken it into 2 longs. Is there an easier way to convert ascii hex values to numbers that can be used for math? I can include the rest of the code, but this is the part I'd like to simplify. I'm checking to see if the current BUFFER value is a number or a letter, and then subtracting the appropriate amount to get the hex value.
Code:
BUFFER VAR BYTE(10)
FOR COUNTER = 0 TO 4
IF BUFFER(COUNTER) < 58 THEN
LOWVAL = LOWVAL * 16 + (BUFFER(COUNTER) - 48)
ELSE
LOWVAL = LOWVAL * 16 + (BUFFER(COUNTER) - 55)
ENDIF
IF BUFFER(COUNTER + 5) < 58 THEN
HIGHVAL = HIGHVAL * 16 + (BUFFER(COUNTER + 5) - 48)
ELSE
HIGHVAL = HIGHVAL * 16 + (BUFFER(COUNTER + 5) - 55)
ENDIF
NEXT
If I scan a tag with value 3600A397A8, I will end up with the ascii equivalent of each digit in BUFFER. The code above takes BUFFER and makes 2 long variables containing 3600A and 397A8. And yes, I already noticed my high and low values are swapped with regard to lsb.