On Thursday 24 February 2005 01:33 pm, Mike Morris wrote: > Hi, > > I'm wondering if anyone has any clever algorithms for performing 16 bit > integer division by a constant using the multiply instruction in the 18F > instruction set. I've looked over the many standard division routines, and > thought perhaps there may be ones that employ the hardware multiply to > really speed things up. > > Specifically, I need to scale a number (0 - 65535) to 0 - 2730 (hence a > divide by 24.) Maybe I'm missing a real obvious approach, but I'd > appreciate any suggestions anyone might have. Multiply by 2731 then shift right. X = (value * 2731) >> 16; -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist