Skip to content

Times seven using shifts and subtraction

Question

How can an integer xx be multiplied by 77 quickly without using the multiplication operator?

Short answer

Compute (x << 3) - x. Shifting left by 33 bits multiplies by 88, and 8x−x=7x8x-x=7x. Shifts and subtractions are single cheap instructions; overflow behaves as with ordinary multiplication.

Adapted from Zhou, A Practical Guide to Quantitative Finance Interviews, sec. 7.2 The Power of Two, 'Multiplication by 7', p.181; question and answer rewritten by SelfMadeQuant.com.

See the hint and the full worked solution in the question bank (free account).

Open the worked solution

Lessons behind this question