Thursday, June 4, 2009

Binary Fingers

There are 10 kinds of people. Those who understand binary, and those who don't.

Using both hands, most people can only count up to ten. They call it "base ten," but it's really base one--one finger for each numeric value until you run out of fingers at ten. This is the world of the mathemetically impaired. Straightforward, uncomplicated, and adequate for doing math up until you get to the first grade.

I, however, can count up to 1023.

Buyah!!

Fingers, it turns out, naturally conform to one of two states: extended (that's a one) or not extended (that's a zero). So, my thumb can be 2^0, my index finger can be 2^1, my middle finger can be 2^2, my ring finger can be 2^4, etc.

Here's a pic where I count up to sixteen. (Note, in computers we use the letters A through F for the numbers 10 through 15--it's a geek thing). If I use all ten of my fingers, I can go up to 2^11 - 1, which is 1023.



When using this technique, I recommend holding your hand low so your fingers point down. That way when you get to 4, people aren't as likely to get offended. Just a little hint.

Converting from binary to decimal is a snap. You only need to remember your powers of two. Here's how you do it.

  • Thumb is 1
  • Index finger is 2
  • Middle finger is 4
  • Ring finger is 8
  • Pinky is 16

You get the idea.

So, to convert from binary to decimal, just add up the fingers that are extended. So, if I have my thumb, index, and middle finger extended, that's 7. If I have my middle finger and my ring finger extended, that's 12 (or A, if you're a geek). If I have all five extended, that's 31.

See how easy it is?

Now for the fun part.

Doing addition in binary is a snap. Here's the basics:

 0      0     1     1
0 + 1 + 0 + 1 +
----- ----- ----- -----
0 1 1 10

 

Most of this you should still remember from Kindergarten, right? It's 1 + 1 that throws most people. Since we've run out of digits (there being only two), we have to carry over to the next column, and that gives us 10--and no, we don't say "ten", we say "one, zero". This is base two, remember? "ten" doesn't exist. Just get it out of your head.

So if we wanted to add, say 0101 to 1001, we would do it like this (Remember to carry the 1 in the right-most column.)

 0101
1001 +
--------
1110

 

If you really want to get into it, you can use your left pinky as a sign bit, and do negative numbers. This cuts your positive range in half, but you can go from +511 to -512. I recommend using 2's compliment instead of 1's compliment. Addition and subtraction are the same (binary is so cool!). What's more, using Booth's Algorithm, you can do multiplication. Your range for the two operands is limited to -15 to +16 (that's five fingers for each number you want to multiply). Your result will be all ten fingers. For division, it will be in reverse. Your numerator will use all ten fingers, and the denominator will use five.

You will have to have 2's compliment down before Booth's algorithm makes any sense, but it is pretty straightforward. Google it, if you're interested.

Some would argue that memorizing the times tables up to 16 would be easier. That might be true for some people. In computers we make trade-offs like this all the time. We use memory when memory is abundant, and we use algorithms when memory scarce.

Some would argue that it would be faster to just use a calculator.

Calculators are for wusses.

1 comment:

  1. Thanks for sharing this information with us. I am a big fan of reading, thanks for sharing this wonderful information.
    Lenovo laptops

    ReplyDelete