How programmers multiply

This afternoon, a discussion about base64 strings prompted the question “How much is 64^2?”. I didn’t have a calculator in hand, and I figured I should be able to calculate 64*64 in my head. The thought process went something like this:

64 is 256/4, and I know by heart that 256 = 2^8, and 4 = 2^2, thus 64 = 2^(8-2) = 2^6.

By the same method, 2^6 * 2^6 = 2^(6+6) = 2^12.

I have memorized a few more powers of two besides 256, and the easiest to remember is 2^10 = 1024.

2^12 = 2^10 * 2^2, so the answer I’m looking for is 1024 * 4 = 4096.

64^2 = 4096. Easy to do in your head when you know arithmetic (or you’ve worked too much on CPUs that don’t have MUL or DIV operators).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.