> Date: Mon, 21 Aug 1995 07:45:52 -0800 > From: Ross Lyle > There has been a lot of discussion about BCD to Binary recently, but how > bout the other way. The "Embedded Control Handbook", page 5-120 has a > 16 bit to BCD listing but can take up to 885 clock cycles. Anything more > efficient out there? I need only a 10 bit to BCD routine (actually up to > 999 ). > Ross Lyle > Victoria, BC <--- hey, that's where my sisters live! Well, I did a binary to bcd routine that handled up to 512. You could modify it to do 1024 without too much trouble, I suppose. I used the fact that x / 100 = (x/2) / 50, much like the BCD->binary routines. Using (x/4) / 25 to generate the hundreds digit will allow eight bit subtractive calculation. Then you calculate (x/4 mod 25) * 4 + (x mod 4 ) and count the tens, leaving the ones. I wasn't concerned about time of execution, a millisecond wasn't a problem for me. I was concerned about RAM/ROM usage. But I don't have the code handy. Tim Braun | Voice: 204-942-2992 ext 228 Continental Healthcare Systems Canada | FAX: 204-942-3001 1900-155 Carlton St | Email: tim@chs.mb.ca Winnipeg, Manitoba, Canada R3C 3H8 | www: http://www.chs.mb.ca/~tim/home.html