16bit divide by 10
David E. Queen <MITVMA.MIT.EDU> wrote: PICLIST
> I can save 600bytes in a lookup table if I can figure out a good way
> to divide a 16 bit number by 10.
> I have the app notes with the general 16 math, but I need a smaller
> and faster routine.
Didn't I just post a divide-by-5 routine here? Oh, well... Must have
been that other PIC list.
Here's a 16-bit divide-by-10 algorithm (y = x/10):
y = x/4
for i = 1 to 7
y = x - y
y = y/4
y = y/2
This works for both signed and unsigned x; if you can deal with a
very slight rounding error, you can speed the routine up by iterating
only 5 times, rather than 7.
Andrew Warren - ix.netcom.comfastfwd
Fast Forward Engineering, Vista, California
See also: www.piclist.com/techref/method/math.htm?key=divide
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the