Welcome to the Geek Author series on Computer Organization and Design Fundamentals. I’m David Tarnoff, and in this series we are working our way through the topics of Computer Organization, Computer Architecture, Digital Design, and Embedded System Design. If you’re interested in the inner workings of a computer, then you’re in the right place. The only background you’ll need for this series is an understanding of integer math, and if possible, a little experience with a programming language such as Java.
In this episode, we are going to go back to the basics – counting, or more importantly, how a computer counts.
The typical portrayal of a child learning to count involves fingers, right? Do you remember counting on your fingers? I don’t, but it is common to see a child showing an adult how old they are by holding up their fingers, right?
So what is the first number you can represent with your fingers? It turns out that it’s not one, it’s zero, represented during that moment before the first finger is raised. This may not seem important to a preschool child, but it is important to note that the non-negative number from which all computers start counting is zero.
Let’s go to the other end of the scale. What’s the highest number you count up to on your fingers? Ten? Well, that’s what most people say. If you’d asked an ancient Sumerian, however, you might have gotten answer like twelve, or sixty, or even 144! 1 Wait a minute, I only have ten fingers! Did ancient Sumerians have twelve fingers, or sixty, or one hundred and forty-four?
Although twelve fingers might have been really cool, the Sumerian wouldn’t have been counting his or her fingers. They would have been counting their finger joints. By using the right thumb as a pointer, you can count the joints of the fingers on your right hand in a sequence. When you get to the last joint of your last finger, you will have reached twelve.
By bringing your left hand into the picture, you could keep track of how many times you’d counted to twelve on your right hand. One way to do this is to use one of the five fingers of your left hand to point to one of the twelve knuckles on your right. Start with the left thumb and count one to twelve, then switch to the left index finger and count one to twelve, then the middle, and then the ring, and lastly the pinkie.
With one of five fingers pointing to one of twelve knuckles, you had five times twelve or sixty possible numbers. If you pointed to the sixth knuckle on your right hand with the fourth finger of your left hand, that would mean you were six knuckles into your fourth pass through twelve. In other words, you’d counted to twelve three times, which is thirty-six, and then counted up to six, which makes the total thirty-six plus six or forty-two.
Let’s up the ante. If you used a count of the finger joints on your left hand to keep track of the number of times you’d counted the finger joints on your right hand, then that would be twelve times twelve or 144.
Now, this is very different than counting to ten on your fingers or even counting the twelve on the knuckles of one hand. When you are counting with ten fingers, you are using all of your fingers to represent a single digit, specifically the one’s place in a decimal or base-ten numbering system. If you put two people together, one person can keep track of the one’s place while the other keeps track of the ten’s place. When counting, each time the first person gets to ten, the second person increments their count by one. Three people could then count up to 999. That’s a lot of fingers.
By using the thumb to point at one of the knuckles on that hand, we can represent the one’s place in a base-twelve numbering system. When we bring in the second hand, we’ve made a two digit base-twelve system with the right hand representing the one’s place and the left hand representing the twelve’s place. So if I’m pointing at the fifth knuckle of my left hand with my left thumb and pointing to the seventh knuckle of my right hand with my right thumb, the number I’ve created is five twelves plus seven ones or sixty-seven. The tenth knuckle on my left hand and the eleventh knuckle on my right hand would be 120 plus eleven or 131. Note that for this system to work properly, we would need to start numbering our knuckles at zero.
So what could this possibly have to do with computers counting? Well, let’s take this down to the digit, literally, your digits. If instead of using all of your fingers to represent a single base-ten digit, allow each finger to represent a digit of its own. The result would be a ten digit number. If we keep this simple and ignore the knuckles, we can use a retracted finger to represent a zero while an extended finger represents a one.
The first digit, say the little finger or pinkie of my right hand, could represent the one’s place. Retracted, that’s a zero, extended, that’s a one, and now I’ve run out of values I can represent with one finger. So I retract the pinkie and count up with the next digit, the ring finger. (Uh, that actually hurts a bit.) That means that the ring finger represents the two’s place. Extending the pinkie and the ring fingers together gives us two plus one or three. If we add one to three we get…um…let’s move along, shall we? The middle finger and the pinkie together give us five. The middle and ring give us six. You get the idea.
Counting like this gives us the base-two or binary numbering system. Each finger, or digit, of our hand is either retracted, a logic zero, or extended, a logic one. Going right to left, each of these binary digits or bits is twice the magnitude of the digit to the right, meaning that each finger represents a different power of two in increasing powers from right to left.
Now replace your fingers with transistors. Just like the fingers, each transistor represents a bit containing a logic zero or a logic one. If we group a bunch of these transistors together, one transistor is assigned to the one’s place, or 20, the next transistor can represent the two’s place, which is 21, the next transistor could represent 22 or four, and so on. Grouping the bits together and allowing each bit to represent a different power of two can give us a non-negative integer.
So how high can we count with transistors in binary? A common way to group transistors is in a block of eight. From right to left, the individual transistors of this group represent the one’s place, the two’s place, the four’s place, the eight’s place, the sixteen’s place, the thirty-two’s place, the sixty-four’s place, and the 128’s place. That means if all of the transistors are on, in other words, each transistor contains a logic one, then they represent the number 1 + 2 + 4 + 8 + 16 +32 + 64 + 128. This equals 255. (If you recall, we discussed in the pulse-width modulation episode that 255 would be an important number. Well, here it is. It’s the highest number we can represent with eight bits.)
Assume we try to add one to this number. When you add one to one in a binary system, this resets the bit to zero and forces a carry to the next highest bit. This carry would then be added to the one in the next position and would continue to propogate through each successive bit until a carry popped out of the top bit. This is actually an attempt to pass a carry to the 9th bit, in other words, the 28 position.
This makes sense since 28 is 256, which is one more than 255.
If we generalize this to some arbitrary number of bits like n, then we see that the n bits are used to represent the one’s place, the two’s place, the four’s place, and so on. We would exhaust the n bits when we get to the 2(n-1) position. That means that the highest number we could count to with n bits is n ones. Add one to that and all of the n bits will reset back to zero with an attempt made to increment the next column which represents the two to the n-th position. That means that the largest number we can represent with n bits is one less than two to the n.
That brings us back to the question, “How high can you count on your fingers?” Well, if you treat each of your fingers like a binary digit, in other words, it’s either on or off, up or down, extended or retracted, then each digit could be viewed as a bit of a ten-bit binary number. With ten digits, you can count up to, well, 210 minus one or 1,023. Wow! Now if only you could extend your ring finger without all the other fingers wanting to join it.
In our next episode, we will discuss some of the methods to convert between decimal and binary and learn some ways to play with these binary numbers on our computer and in our code. Until then, remember that while the scope of what makes a computer is immense, it’s all just ones and zeros.
References:
1 – Mastin, L. (2010). Sumerian/Babylonian Mathematics. Retrieved February 14, 2019, from The Story of Mathematics: http://www.storyofmathematics.com/sumerian.html