Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
CSDb User Forums


Forums > C64 Coding > 24 bit hex value to decimal 8 digit screen output ?
2016-03-04 00:39
la-style

Registered: Sep 2003
Posts: 42
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 ?
2016-03-04 01:03
Oswald

Registered: Apr 2002
Posts: 3947
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.
2016-03-04 07:39
Hoogo

Registered: Jun 2002
Posts: 76
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..
2016-03-04 08:17
soci

Registered: Sep 2003
Posts: 299
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.
2016-03-04 08:34
MagerValp

Registered: Dec 2001
Posts: 860
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.
2016-03-04 08:34
YPS

Registered: Oct 2012
Posts: 2
I like this solution:

http://codebase64.org/doku.php?id=base:32_bit_hexadecimal_to_de..
2016-03-04 09:08
ChristopherJam

Registered: Aug 2004
Posts: 474
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..
2016-03-04 21:26
Oswald

Registered: Apr 2002
Posts: 3947
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.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Hammerfist/Desire
Almighty God/L64/Ons..
Scarzix/Offence
Romppainen/ΤRIΛD
Guests online: 38
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 Coma Light 13  (9.6)
4 Lunatico  (9.6)
5 Comaland 100%  (9.5)
6 Incoherent Nightmare  (9.5)
7 Wonderland XII  (9.5)
8 Comaland  (9.5)
9 Fantasmolytic  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Dawnfall V1.1  (9.7)
2 Globe 2016 [reu]  (9.7)
3 Daah, Those Acid Pil..  (9.4)
4 Treu Love [reu]  (9.4)
5 Dawnfall  (9.3)
6 One-Der  (9.2)
7 Hardware Accelerated..  (9.2)
8 Goatbeard  (9.2)
9 Safe VSP  (9.2)
10 Ächzzeit  (9.1)
Top Groups
1 Censor Design  (9.4)
2 Booze Design  (9.4)
3 Oxyron  (9.3)
4 Crest  (9.3)
5 Nostalgia  (9.3)
Top Hardware-Gurus
1 Zer0-X  (10)
2 Soci  (9.9)
3 Wiesel  (9.9)
4 Lemming  (9.8)
5 Grue  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2016
Page generated in: 0.295 sec.