piclist 1996\06\05\210643a >
Thread: 16bit divide by 10
www.piclist.com/techref/method/math.htm?key=divide
BY : 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.
//

UINT16
DivideBy10 (
UINT16 Dividend
)
{
UINT16 Quotient;
UINT32 Temp;

Temp = (UINT32) Dividend;
Temp = (Temp * 52429) >> 19;
Quotient = (UINT16) Temp;

return Quotient;
>}

This technique is used by high-performance compilers since
a multiplication and a shift is almost always faster than
a division.

Tom
<c=US%a=_%p=Digital%l=NTMAIL2-960606005633Z-3306 @ntmail3.zso.dec.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

new search...