A Lesson On Binary

By Joshua Erdman
Digital Foundation

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 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 signal for each. In other words, it is not as simple as if there is a signal, it is a 1 and the lack of a signal represents a 0. The way binary works is by registering a high signal and a low signal.

Bits and bytes

A bit is a single binary digit. This is a useless amount of information but when you group them together nd 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 wierd by now but you can probably see the pattern and can guess what the number 10 is in binary. It is 1010 (the fact that there is 2 tens in a row is a coincidence.

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 onmly goes 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. So we cannot flag 16 because that will put us over 237. The next digit to flag is 8, we skip 4, 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 was with decimal numbers, the largest most significant number is on the left and the digit with the smallest numberical value is on the right.

Converting from Binary

Now that we know the decimal value of each binary digit, converting back to decimal is a piece of cake. Again just write out your decimal equivalents for each binary digit. So if you were given the binary number 1101011001 you would count the number of digits, 10, and then 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