July 2002
Intermediate to advanced
320 pages
8h 15m
English
Rather than coding algorithm magic, we can provide a table that gives the magic numbers and shift amounts for a few small divisors. Divisors equal to the tabulated ones multiplied by a power of 2 are easily handled as follows:
1. |
Count the number of trailing 0’s in d, and let this be denoted by k.
|
2. |
Use as the lookup argument d/2k (shift right k).
|
3. |
Use the magic number found in the table.
|
4. |
Use the shift amount found in the table, increased by k.
|
Thus, if the table contains the divisors 3, 5, 25, and so on, divisors of 6, 10, 100, and so forth can be handled.
This procedure usually gives the smallest magic number, but not always. The smallest positive divisor for which it fails in this respect for W = 32 is ...
Read now
Unlock full access