Hex to BCD conversion routine

MrChips

Joined Oct 2, 2009
30,824
Ok, this time multiply by 10 twice (ie. to multiply by 100)

and display only the hi-byte as result. Tell me what you get!
 

MrChips

Joined Oct 2, 2009
30,824
Ok, let's back up for a minute so I can understand your system.

Your hardware consists of two digits displaying hex after the decimal point?
When you call bcd how can you get 8E or 8C displayed?

If you pass 99d to call bcd what is displayed?
If you pass 130d to call bcd what is displayed?
 

MrChips

Joined Oct 2, 2009
30,824
Please answer the questions.

Does your hardware consist of two digits displaying hex after the decimal point?

If you pass 99d to call bcd what is displayed?

If you pass 130d to call bcd what is displayed?

(If you no longer need help please tell me. I can always call it quits.)
 

Thread Starter

RG23

Joined Dec 6, 2010
304
yes I display two digits displaying hex after the decimal point
for d'99' I get 63

for d'130' I get 82
 

MrChips

Joined Oct 2, 2009
30,824
Now I get the picture.

Here is the algorithm:

Step 1
Multiply X_FracH by 10 (using 8 x 8 -> 16-bit result)
Save the hi-byte only as say D1 (make sure you are saving the hi-byte only)

Step2
Multiply X_FracH by 100
Save the hi-byte only as say D2

Step 3
Take D1 and multiply by 10 (only 8 x 8 -> 8-bit result required)
Save single lo-byte only as say D10

Step 4
Subtract D10 from D2 and save this byte as D0.

Step 5
Multiply D1 by 16 (simply shift left 4 bits - use single byte only)

Step 6
Add D0

Step 7
call bcd


over and out!
 

MrChips

Joined Oct 2, 2009
30,824
Geez... This is not an opinion. This is the answer.
You take a few months to get nowhere and I give you the answer in 15 mins... such gratitude!
 
Last edited:
Top