www.piclist.com/techref/method/math.htm?key=divide

David E. Queen <PICLISTKILLspam@spam@MITVMA.MIT.EDU> wrote:

> 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.

David:

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

next i

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.

-Andy

Andrew Warren - EraseMEfastfwdTakeThisOuTix.netcom.com

Fast Forward Engineering, Vista, California

http://www.geocities.com/SiliconValley/2499

See also: www.piclist.com/techref/method/math.htm?key=divide