A Lesson On Binary


Binary is the way of the computer. All commands, memory storage, input, and output are done using binary in the computer. Computers think and communicate in binary, the same goes for computer addresses. To really get a handle on network addressing, SCSI IDs and other important computer theories, we need to be able to use binary.

Binary is just 1s and 0s right?

Not really, for computers to register a 1 or a 0 it needs a separately distinct signal for each. In other words, it is not as simple as: “the presence of a signal represents a 1 and the lack of a signal represents a 0”. Instead, the way binary works is by registering a high signal for 1s and a low signal for 0s.

Bits and Bytes

A bit is a single binary digit. This is a useless amount of information but when you group them together and have 8 bits, this makes one byte. A single byte can have up to 256 different combinations of 1s and 0s. Typically information is broken up into bytes to be stored, calculated, or transmitted.

Binary Counting

The way we are all used to counting is by using the numbers 0 through 9. Then when we start all over again, we put a 1 for the first digit and increment the second digit from 0 to 9 again. The same goes for binary, except that we can only use the numbers 0 through 1. Check out the counting below:

        Decimal         Binary
          0                0
          1                1
          2               10
          3               11
          4              100
          5              101
          6              110
          7              111
          8             1000
          9             1001

Ok so I know this is looking pretty weird by now but you can probably see the pattern and can guess what the next number is in binary. The Decimal equivalent of 10 (ten) is 1010 (the fact that there is 2 tens in a row is a coincidence).

CLUE: If you make each of your fingers represent a binary digit, you can count to ten with just 4 fingers. In the paragraph above the number ten is represented in binary as 1010, so hold your right hand up showing four fingers, then drop your middle finger and your pinkie, that is ten in binary. How high can you count with all ten fingers? Find the answer at the end of this article.

Converting to and from binary

But there has to be a better way to convert decimal numbers to and from binary. With the table above we only counted to 9 in decimal and it is already quite large. The solution to that problem is pretty easy with a few observations. Look back at the example. The number 1 is the same in both columns. Then look at number 2, in the binary column it is a 1 followed by a zero, then look at 4 and 8, these are also a 1 followed by zeros. The same goes for 16, 32, and so forth. And the relationship between, 1, 2, 4, 8, and 16 is they are all powers of 2. (2 to the power of zero is 1 – in case if you were wondering).

Clue: The decimal equivalent to each binary digit is by powers of 2. (Example: The third binary digit’s decimal equivalent is 2 to the 3rd power. The fourth binary digit’s equivalent value is 2 to the 4th power, and so on.)

Conversion in action

Converting to binary

First you must create a line listing the powers of two to just beyond the number you want to convert. In other words, if you want to convert 237 to binary, list all the powers of two until you reach 256. This will ensure you have all the binary bits available to you. Check out the example:

    256   128   64   32   16   8   4   2  1

Now flag each digit needed to add up to 237 starting from the left. So we would not flag 256 since that is too big, the first power of two we will flag is 128. Then 64 and 32. So far this adds up to 224.

    256   128   64   32   16   8   4   2  1
    -----------------------------------------
            1    1    1

Remember we need to flag the binary digits that add up to 237. We only have 224 so let’s keep going. We cannot flag 16 because that will put us over 237. The next digit to flag is 8, we skip 4 (too large), and flag the 2 and 1. So our flagging should look like this:

    256   128   64   32   16   8   4   2  1
    -----------------------------------------
            1    1    1        1       1  1

Notice I flagged each digit I needed with a 1. By now I am sure you have figured out that the digits I do not need will be flagged with a 0. See below:

    256   128   64   32   16   8   4   2  1
    -----------------------------------------
      0     1    1    1    0   1   1   0  1

Now just as with our normal counting, we do not have any number prefixed with a zero. In other words if I was to display the digits for nine hundred fifty seven I would not write 0957. It would only be the digits that are significant, 957. So that is it, the binary version of 237 is: 11101011.

Clue: Just as with decimal numbers, the largest most significant number is on the left and the digit on the right is the least significant.

Converting from Binary

Now that we know the decimal value of each binary digit, converting back to decimal is a piece of cake. This time we will convert the binary number 1101011001 to decimal.

First write out your decimal equivalents for each binary digit. Since this binary number 1101011001 is made up of 10 bits we need to write out the first 10 powers of two (starting from right to left):

    512 256  128  64  32  16  8  4  2  1

Then write your binary number under the values.

    512 256  128  64  32  16  8  4  2  1
    ------------------------------------
      1   1    0   1   0   1  1  0  0  1

Finally add up each binary value that is flagged with a 1.

     512
     256
      64
      16
       8
     + 1
     ___
     857

Everybody say “Thanks” to Joshua Erdman

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