Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 19th November 2004, 11:12 PM   (permalink)
Default Algorithm to convert 64 bit Binary to BCD

Does anyone have such an algorithm? Or something similar?

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

Len
ljcox is offline  
Old 20th November 2004, 04:38 AM   (permalink)
Default

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?
bonxer is offline  
Old 20th November 2004, 06:21 AM   (permalink)
Default

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
StupidDum is offline  
Old 20th November 2004, 07:06 AM   (permalink)
Default Re: Algorithm to convert 64 bit Binary to BCD

Quote:
Originally Posted by ljcox
Does anyone have such an algorithm? Or something similar?

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

Len
look up table .. Right Nigel... :wink:
williB is offline  
Old 20th November 2004, 07:06 AM   (permalink)
Default Re: Algorithm to convert 64 bit Binary to BCD

Quote:
Originally Posted by ljcox
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 20th November 2004, 11:44 PM   (permalink)
Default

Thanks for the responses, gives me food for thought.

Len
ljcox is offline  
Old 21st November 2004, 04:34 AM   (permalink)
Default Re: Algorithm to convert 64 bit Binary to BCD

Quote:
Originally Posted by Nigel Goodwin
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.
samcheetah is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 03:21 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker