### Site Tools

base:hexadecimal_to_decimal_conversion

# Differences

This shows you the differences between two versions of the page.

 base:hexadecimal_to_decimal_conversion [2015-04-17 04:32]127.0.0.1 external edit base:hexadecimal_to_decimal_conversion [2020-11-14 23:09]mace Added/moved redirections to other routines at the top 2020-11-14 23:09 mace Added/moved redirections to other routines at the top2015-04-17 04:32 external edit 2020-11-14 23:09 mace Added/moved redirections to other routines at the top2015-04-17 04:32 external edit Line 1: Line 1: ====== Hexadecimal to Decimal Conversion ====== ====== Hexadecimal to Decimal Conversion ====== Without division or multiplication, this first routine takes an 8-bit hex number and returns a 10-bit decimal (BCD) number. It is done by the "add three" algorithm from Motorola AN-757, "Analog-to-Digital Conversion Techniques With the 6800 Microprocessor System" by Don Aldridge. Motorola apparently does not have the app. note on their website. I converted it in the 80's for a 65c02 product. Start with the input number in accumulator. Without division or multiplication, this first routine takes an 8-bit hex number and returns a 10-bit decimal (BCD) number. It is done by the "add three" algorithm from Motorola AN-757, "Analog-to-Digital Conversion Techniques With the 6800 Microprocessor System" by Don Aldridge. Motorola apparently does not have the app. note on their website. I converted it in the 80's for a 65c02 product. Start with the input number in accumulator. + + See also [[More Hexadecimal to Decimal Conversion]]. Andrew Jacobs has written equivalent routines to the ones presented here, eliminating the lookup tables in exchange for a little slower execution speed. + + If you need a routine that decodes hex to plain ascii, try [[Another Hexadecimal to Decimal Conversion]]. ; A       = Hex input number (gets put into HTD_IN) ; A       = Hex input number (gets put into HTD_IN) Line 116: Line 120: Note by Karoshier: The above code can be easily made a little faster and shorter by splitting the data table into three separate tables, one for the low digits, one for the mid digits and one for the high digits. This way the index can be initialized to 15 instead of 45 and be decremented by 1 instead of 3, thereby saving 4 cycles per iteration and making the routine shorter by 2 bytes. If you have space constraints and you need an 8 bit version as well, you can also make the 16 bit version work for both 8 or 16 bits by changing the initial value of X according to the needs (namely 3 times 7 instead of 3 times 15) and patching the ROL opcode on the fly to a BIT instruction, which does not alter the carry. Note by Karoshier: The above code can be easily made a little faster and shorter by splitting the data table into three separate tables, one for the low digits, one for the mid digits and one for the high digits. This way the index can be initialized to 15 instead of 45 and be decremented by 1 instead of 3, thereby saving 4 cycles per iteration and making the routine shorter by 2 bytes. If you have space constraints and you need an 8 bit version as well, you can also make the 16 bit version work for both 8 or 16 bits by changing the initial value of X according to the needs (namely 3 times 7 instead of 3 times 15) and patching the ROL opcode on the fly to a BIT instruction, which does not alter the carry. - - See also [[More Hexadecimal to Decimal Conversion]]. Andrew Jacobs has written equivalent routines to the ones presented here, eliminating the lookup tables in exchange for a little slower execution speed.
base/hexadecimal_to_decimal_conversion.txt ยท Last modified: 2020-11-14 23:09 by mace