Integer Division by Constants
Prev: Integer Division
Next: Some Elementary Functions
Sections
10-1Signed Division by a Known Power of 210-2Signed Remainder from Division by a Known Power of 210-3Signed Division and Remainder by Non-Powers of 210-4Signed Division by Divisors10-5Signed Division by Divisors10-6Incorporation into a Compiler10-7Miscellaneous Topics10-8Unsigned Division10-9Unsigned Division by Divisors10-10Incorporation into a Compiler (Unsigned)10-11Miscellaneous Topics (Unsigned)10-12Applicability to Modulus and Floor Division10-13Similar Methods10-14Sample Magic Numbers10-15Simple Code in Python10-16Exact Division by Constants10-17Test for Zero Remainder after Division by a Constant10-18Methods Not Using Multiply High10-19Remainder by Summing Digits10-20Remainder by Multiplication and Shifting Right10-21Converting to Exact Division10-22A Timing Test10-23A Circuit for Dividing by 3
Problems
-
Show that for unsigned division by an even number, the
shrxiinstruction, or equivalent code, can be avoided by first (a) turning off the low-order bit of the dividend, and operation, [CavWer] or (b) dividing the dividend by 2, shift-right-1 instruction, and then dividing by half the divisor. -
Code a function in Python similar to that of Figure 10-4 on page 240, but for computing the magic number for signed division. Consider only positive divisors.
-
Show how you would use Newton’s method to calculate the multiplicative inverse of an integer modulo . Show the calculations for .