Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Algorithm to convert 64 bit Binary to BCD

Status
Not open for further replies.

ljcox

Well-Known Member
Does anyone have such an algorithm? Or something similar?

I don't want to have to re-invent the wheel.

Len
 
That's quite a significant amount of digits. Are these to be displayed, such as an on an LCD? In that case, converting them to ASCII would be better. You aren't planning on stringing up an unholy number of seven-segment displays to a poor little PIC are you :?: What is your application?
 
well, I did convert 40-bits to BCD long time ago.
but..hm... couldnt understand my own code when i look at it now

to convert 8 bit to BCD, it could be done by using divisio by 10 to get quotient and remainder.(refer to college book on digital circuit)

the tough part is to convert 64 bit when ur microcontroller is only 8 bit.

take out a piece of paper, calculate by hand, 123456 / 10.

The 1st step u do to divide 123456 by 10 is to divide 12 by 10, get the remainder, which is 2. Then multiply 2 with 10 and add the following digit, 3, to make it 23. Then u divide 23 with 10... and so on. got it?

you will get 12345 as quotient, and 6 as remainder. The '6' will be the least significant bit of BCD. Repeat the step, you will get 5, then 4... and eventually 1.

to do it in 8 bit, first, divide MSB by 10, get the quotient and remainder.
Then, multiply the quotient with 256 instead of 10 (cause 1 byte=256) and add with the following byte. Therefore, u need to define the quotient as 16 bits. The rest of the steps are identical with above.

confusing? yea.. even me myself not sure what i'm talking about. pls forgive me i give wrong information mistakenly
 
ljcox said:
Does anyone have such an algorithm? Or something similar?

I don't want to have to re-invent the wheel.

What processor is it for?, you can probably do a search and find existing code to do it!.

I'm presuming that you're looking for Binary to Decimal (and not actually BCD), everyone seems to incorrectly use BCD these days. BCD is packing two decimal digits in one 8 bit byte, some older processors even had special modes to do maths on BCD bytes - which was extremely useful.
 
Nigel Goodwin said:
BCD is packing two decimal digits in one 8 bit byte, some older processors even had special modes to do maths on BCD bytes - which was extremely useful.

yeah the 8085 has special instructions for BCD numbers like DAA (Decimal Adjust Accumulator) and there is also a status flag for Auxillary Carry which is used in BCD calculations.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top