piclist 1996\05\28\173722a >
Thread: 16bit divide by 10
www.piclist.com/techref/method/math.htm?key=divide
face
flavicon
face BY : fastfwd@spam@@TakeThisOuTix.netcom.com



David E. Queen <PICLIST.....spamspamBeGoneMITVMA.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 - EraseMEfastfwdspam@spam@ix.netcom.com
Fast Forward Engineering, Vista, California
http://www.geocities.com/SiliconValley/2499
<199605282136.OAA09912@dfw-ix4.ix.netcom.com>

See also: www.piclist.com/techref/method/math.htm?key=divide
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) 16bit divide by 10

month overview.

new search...