Sunday, 10 June 2012

A (hopefully) simple Explanation of the Binary numeral system


Introduction


Hi! I am a software developer, and I can count to 32 with my fingers on just one hand.

Most people can count to 5 with their fingers.

How does that work? Well, imagine that you are counting with the fingers of your hand. Let's say you wish to indicate the number 1. No doubt you'd use your index finger. But it is of course also possible to use your thumb. When you think about it there are five different ways to indicate that you mean 1. This is terribly inefficient.

Instead of having 5 different ways to indicate the number 1, we can assign different numbers to the different fingers.

What you are, in fact, doing is no longer using how many fingers to determine the number, but which fingers.

This is what we all have been doing with the decimal system since we could count. When I ask you if there is a difference between the numbers 21 and 12, you say of course. But why is that? We are still using the same two digits, are we not? The answer is in the position of the two numbers.

The decimal system, the system we are dealing with every day, is called a positional notation with a radix of 10. The finger counting system explained above is called the binary numeral system, which is a positional notation with a radix of 2.

An Abacus

Whilst old people still know what an Abacus is, young people have no clue. An example of an Abacus using the Decimal numeral system that everybody knows is visible at the top of this article.

“The abacus is a device, usually of wood, having a frame that holds rods with freely-sliding beads mounted on them.”[1]

A Binary Abacus would look something like this[2]:

In the example above, one row on the abacus represents a “bit”, a value that is either 0 (no bead) or 1 (a bead). The combination of the 8 rows together make 256 combinations of beads possible. This is called a “byte”.

In the picture, all beads are "on", so the maximum value is displayed, 255.

Why?

Why do computers use a Binary numeral system? Why not have them use a Decimal numeral system, like we do? Wouldn't that make it easier?
That would make it easier for us, not easier for the computers. The reason for this is that computers are one of the most complicated machines we have. There are some advantages to computers dealing with binary numbers:
  • binary is easy for a computer, either it's on or off (yes or no, true or false, 1 or 0, electricity or no electricity). There's no ambiguity about it.
  • it is fault tolerant, which means that a computer can easily determine if the value was 1 or 0, even if there has been some problem. After all, there are only two options. If a transistor received 1.3 V instead of 1.5, the value is still a definite 1.
  • it is easier, no difficult hardware needs to be designed to take care of all the intermediate numbers we use like 5 and 6 and 3.

Note

When you think about it, the binary numeral system is also the smallest possible numeral system. Any less digits and you would not be able to count at all!

As you see, radix 2 means that a binary numeral system is always dealing with multitudes of 2. The numbers 1,2,4,8,16,32,64,128,256,512,1024 are numbers any Software Designer knows by heart. It also explains why a number of things dealing with computers are always expressed in multitudes of 2. Examples of these are the 32bits and 64bits processors and the need to always express memory in multitudes of 1024 instead of the 1000 we are used to.

An in depth article and the history of the binary numeral system is available at Wikipedia.[3]

Also, if anybody has any other insights to add to this article, I'd welcome it. I consider this article to be in permanent development.

Appendix A

The following numeral systems are currently in use:

nameradixused
binary2often
octal8rarely/none
decimal10most used
hexadecimal16heavily

Appendix B

The multitudes of 2:

number of bitsunitcomments
1bitoften
2--
4nibble, nybble or even nyble, semioctethalf a byte, corresponds to a single hexadecimal digit. An example of “ha ha only serious”[4]
8byte,octetthe number of bits in a byte
16word, shortvery old processors were only 16 bits
32longprocessors
64-modern processors
128--
256--
512--
1024kiloas in kilobits and kilobytes
10242megamegabytes
10243gigagigabytes
10244teraterabytes

References


[1] A Brief History of the Abacus
http://www.ee.ryerson.ca:8080/~elf/abacus/history.html
[2] Creating A Binary Abacus
http://randomthoughtsonjavaprogramming.blogspot.nl/2012/06/creating-binary-abacus.html
[3] Binary numeral system
http://en.wikipedia.org/wiki/Binary_numeral_system
[4] Ha ha only serious
http://www.catb.org/jargon/html/H/ha-ha-only-serious.html

3 comments:

  1. Hi,
    I got into your article looking for a binary abacus, excellent!
    It's for this "binary numbering" micro-course I'm developing, here: http://ec2-54-227-184-202.compute-1.amazonaws.com:8080/binum.html
    If you don't mind I'll use one abacus image, replacing the silly section with small sheep images.
    Saludos!
    --
    Juan Lanus

    ReplyDelete
    Replies
    1. No, feel free to use one of my images.

      Delete