Searching \ for '10 bit to BCD' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=bit+bcd
Search entire site for: '10 bit to BCD'.

Truncated match.
'10 bit to BCD'
1995\08\21@110357 by

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
Camosun College
Victoria, BC
lylecamosun.bc.ca

> Date:         Mon, 21 Aug 1995 07:45:52 -0800

> 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