16bit divide by 10
Tom Van Baak email (remove spam text)
>Scott Dattalo wrote:
>> Everyone knows a cat has 9 lives. We have used three
>> on this problem, so there are probably six more solutions
>> lurking out there.
If you're willing to call a 16x16 bit multiply subroutine you
can replace constant division with reciprocal multiplication.
Using C for this example:
typedef unsigned short UINT16;
typedef unsigned long UINT32;
// 16-bit divide by 10 without division.
Temp = (UINT32) Dividend;
Temp = (Temp * 52429) >> 19;
Quotient = (UINT16) Temp;
This technique is used by high-performance compilers since
a multiplication and a shift is almost always faster than
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