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).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s