piclist 1996\05\28\173722a >
Thread: 16bit divide by 10
face BY : fastfwdspamBeGone@RemoveMEix.netcom.com

David E. Queen <RemoveMEPICLIST.....spamTakeThisOuTMITVMA.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.


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.


Andrew Warren - spamfastfwdRemoveMEspam@spam@ix.netcom.com
Fast Forward Engineering, Vista, California

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