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