| |
lA-sTYLe
Registered: Sep 2003 Posts: 63 |
24 bit hex value to decimal 8 digit screen output ?
I am looking for a solution that converts a 24 bit hex Value to 8 Digit decimal for displaying on Screen.
Anybody who saw something that might be usefull which i didnt notice yet ? |
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
each hex digit is 4 bit. each byte is made of 2x4bits. 24 bit is made up of 3 8 bit bytes. thus the problem is reductable to a table lookup of 16 elements.
lda byte
and #%00001111 ;converting low 4 bits to screen
tax
lda table_nr_to_hex_digits,x
sta screen
lda byte
lsr
lsr
lsr ;converting high 4 bits to screen
lsr
tax
lda table_nr_to_hex_digits,x
sta screen+1
now you take the 2nd byte and repeat above + change screen location.
now you take the 3rd byte and repeat above.
work out the table and screen locations for yourself. |
| |
Hoogo
Registered: Jun 2002 Posts: 105 |
Oswald, it seems you've forgotten the conversion to decimal.
Does something match from the codebase? https://codebase64.org/doku.php?id=base:io_programming#text_man.. |
| |
soci
Registered: Sep 2003 Posts: 480 |
You may try to convert it to a 32 bit BCD number with the shift+add method. Or use the table of powers of ten method. And of course the repeated division/modulo by 10 works too. |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
6502.org is great for this kind of stuff;
http://6502.org/source/integers/hex2dec.htm
But the general idea is to repeatedly divide by 10 and print the modulo. |
| |
YPS
Registered: Oct 2012 Posts: 5 |
I like this solution:
http://codebase64.org/doku.php?id=base:32_bit_hexadecimal_to_de.. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Hah! I really should have checked codebase before running all those decruncher speed tests, would have meant I could just type the decimal into my results instead of having hex in my json and decimal only in the reports.. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
Quote: Oswald, it seems you've forgotten the conversion to decimal.
Does something match from the codebase? https://codebase64.org/doku.php?id=base:io_programming#text_man..
ofcourse...
note to self: dont give code advice at 01:00 am just woken up in the nightshift. |