For those of you wondering, this algorithm gives decently accurate 10-bit ratios with a Big O of (n^2). I hope some one finds it useful.
Bear in mind that the Numerator MUST be smaller than the Denominator, and that the denominator bit-shifted left to be bigger than the Power of 2 you're trying to fit it in. Therefore, don't change the 1024 to 16384 and expect it to work (while still using 16-bit WORDs).
Code:TenBitRatio: Result=0 while Denominator<1024 Numerator=Numerator<<1 Denominator=Denominator<<1 WEND while Denominator>0 Digit=0 while Numerator>Denominator Numerator = Numerator - Denominator Digit=Digit+1 WEND Denominator = Denominator>>1 Result = Result << 1 Result = Result + Digit WEND




Bookmarks