Handwritten algorithm in 6502 assembly language to convert ASCII characters representing hexadecimal digits ('0'-'9', 'A'-'F') to the corresponding hexadecimal value. Conveniently, ASCII for character '0' is 30 in hex. However, character 'A' (41 in hex) does not follow right after character '9' (39 in hex).
The following algorithm written in #6502assembly checks whether ASCII character loaded in the 8-bit accumulator is a hexadecimal digit ('0'-'9', 'A'-'F'). In case it is a hexadecimal digit, the corresponding value from 0000 to 1111 is stored in the low nibble of the accumulator.