## You are here

Homedoubling and halving algorithm for integer multiplication

## Primary tabs

# doubling and halving algorithm for integer multiplication

Because multiplying and dividing by 2 is often easier for humans than multiplying and dividing by other numbers there is an algorithm for multiplication of any two integers that takes advantage of multiplication and division by 2.

Call the algorithm with two integers.

1. Use one of the integers to start a column on the left and the other to start a column on the right. (Either number can be put in either column, there are very minor optimizations that are unlikely to make a difference in performance, such as not choosing for the left column numbers that end long Cunningham chains).

2. Divide the previous integer on the left column by 2 and write the yield below it, ignoring any fractional part there may be. Multiply the previous integer on the right column by 2 and write the product below.

3. Repeat Step 2 until the yield on the left column is 1.

4. For every even number on the left column, cross out the right column’s number of the same row.

5. Add up the the numbers on the right column that haven’t been crossed out.

For example, to multiply 108 by 255:

108 | $\not{255}$ |

54 | $\not{510}$ |

27 | 1020 |

13 | 2040 |

6 | $\not{4080}$ |

3 | 8160 |

1 | 16320 |

27540 |

This works in any base (as long as one doesn’t get confused about parity in odd bases). For example, 18 times 24 in base 5:

33 | $\not{44}$ |
---|---|

14 | 143 |

4 | $\not{341}$ |

2 | $\not{1232}$ |

1 | 3014 |

3212 |

Naturally one might wonder if this can be applied to binary and used by computers. After all, halving and ignoring the fractional part is even easier: it’s just a matter of shifting the bits to the right, and it doesn’t matter what the computer does with the discarded bit (as long as it doesn’t put it back into the original byte or word in the most significant bit or the sign bit). Doubling is also easy, just a shift left, with the only concern being overflow.

1010 | $\not{111}$ |
---|---|

101 | 1110 |

10 | $\not{11100}$ |

1 | 111000 |

1000110 |

Of course this algorithm is not suitable for large integer multiplication as is required in the search for large prime numbers.

# References

- 1 Paul Erdős & János Surányi Topics in the theory of numbers New York: Springer (2003): 5
- 2 Ogilvy & Anderson, Excursions in Number Theory. Oxford: Oxford University Press (1966). Reprinted New York: Dover (1988): 6 - 8

## Mathematics Subject Classification

00A06*no label found*00A05

*no label found*11B25

*no label found*

- Forums
- Planetary Bugs
- HS/Secondary
- University/Tertiary
- Graduate/Advanced
- Industry/Practice
- Research Topics
- LaTeX help
- Math Comptetitions
- Math History
- Math Humor
- PlanetMath Comments
- PlanetMath System Updates and News
- PlanetMath help
- PlanetMath.ORG
- Strategic Communications Development
- The Math Pub
- Testing messages (ignore)

- Other useful stuff
- Corrections

## Comments

## Strikeout

There's got to be a better way to cross out numbers (or any text) in TeX. Even lowly HMTL can do it.

## Re: Strikeout

> There's got to be a better way to cross out numbers (or any

> text) in TeX. Even lowly HMTL can do it.

Well, you can add

\usepackage{ulem}

to your preamble, then do

This is \sout{not} a test.

Unfortunately, while this appears to work in page

images mode, it does not seem to work in HTML mode.

## Re: Strikeout

Also, if I recall correctly, ulem has the annoying habit of doing things like redefining \emph to do underlines as well, or something like that.

If you got desperate, you could drawn an horizontal line and then translate it...

Cam