# Which is more computationally efficient: multiplication or 0 padding?

On a PC I am implementing an algorithm in which a number from a look table will be chosen randomly, and will be multiplied by 1000 or 10000. Instead of multiplying by 1000 or 10000 I am thinking of simply padding the numbers with the required 0s. This padding will be nothing but some write operations (though random writes) in memory.

Which is more computationally efficient: multiplication or 0 padding?

• Padding by 0's corresponds to multiplying by 2, not 10, so 10 zeroes should correspond to multiplying by 1024. They should however be pretty much the same if you are using, e.g., ints in C++. – Pål GD Jan 31 '13 at 11:56
• If shifting is faster, your compiler (assuming some optimization is requested) does it on its own, or deserves to get replaced. – vonbrand Jan 31 '13 at 16:55
• Looks like a possible case of premature optimisation to me. – Raphael Feb 1 '13 at 10:45

I'm assuming that your numbers are in binary. In this case, 0 padding is shift left: x << 3 is the same as x * 0x08, where 0x08 (hex) is 1000 (binary).