??? 06/29/07 11:21 Modified: 06/29/07 11:22 Read: times |
#141333 - A Different Solution Responding to: ???'s previous message |
Another solution, based on Russell's method. This one's about 5 bytes shorter and provides a way to accept lower-case digits if you want to.
-- Russ ; ----------------------------------------------------------------------------- ; AsciiHexToBinary ; ----------------------------------------------------------------------------- ; DESCRIPTION: This subroutine converts an ASCII hex digit in the accumulator ; to its binary equivalent. It returns with the carry bit ; cleared on success, or set if the input was not a valid hex ; digit. ; ; NOTE: As written, accepts only upper-case hex digits. Uncomment the ; ANL instruction if you want to accept lower-case digits also. ; ; REVISIONS: 29 Jun 07 - RAC - Genesis ; ----------------------------------------------------------------------------- AsciiHexToBinary: add a,#256-'0' ; Convert 0-9 jnc FixCarry ; Result < 0 - bad input cjne a,#10,$+3 ; Result >= 10? jc FixCarry ; No - we're done ; anl a,#NOT 20h ; Yes - convert to upper case subb a,#7 ; Convert A-F cjne a,#10,$+3 ; Is result < 10? jc CarryOk ; Yes - that's bad cjne a,#16,$+3 ; No - check for result >= 16 FixCarry: cpl c ; Fix the carry bit CarryOk: ret ; Return |
Topic | Author | Date |
number in ascii to binary | 01/01/70 00:00 | |
Not sure if this will help but anyways | 01/01/70 00:00 | |
Basic method | 01/01/70 00:00 | |
Needs a bit more error checking | 01/01/70 00:00 | |
Solution | 01/01/70 00:00 | |
A Different Solution | 01/01/70 00:00 | |
I agree | 01/01/70 00:00 | |
thank you![]() | 01/01/70 00:00 |