NetworkClue.com
NetworkClue Home PageHome Contact UsContact ConsultingConsult
Bulletin Board
Internet Services covers Secrets to hosting websites, Hosting your own web server, and using DNS Servers.Operating Systems leads you through the decision of Linux vs. Windows, ideal installations and setups to create an efficient and redundant environment for your business, and great features to make management easier.Routing & Firewalls contains articles that will allow you to take control of your router. Learn how to protect your company with access lists and advanced firewall techniques.Hardware answers the common questions about Switches vs. Hubs, recommends SysAdmin Tools, and recommendations for adequate power protection.Utilities will cover fighting spam, using Anti-Virus programs effectively and the must haves for every administrator's software toolbox.

Bulletin Board

A Lesson On Binary

By Joshua Erdman
Digital Foundation, inc.

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

Final Comments

Yes this would all be MUCH easier if we were to just use a calculator, however when it comes to TCP/IP Addressing or Cisco Access Control Lists the skill of converting to binary becomes essential!

CLUE: With 10 fingers, each finger representing one binary digit, you can count to 2 to the 10th power minus 1 or 1023. The reason why it is not 1024 is that you must include zero (all your fingers being down).

References:

Cisco Access Control Lists

TCP/IP Addresses

Parity

Article last reviewed: 01/09/2006


del.icio.us

Created by: Digital Foundation, inc.

Copyright © 2002-2005 Digital Foundation, inc.   www.networkclue.com

All content of the NetworkClue website is copyrighted. Articles, notes, outlines, and all other materials may not be stored on the Internet or sold or placed by themselves or with other material in any electronic or printed format in whole or part. However materials may be referenced by links to the site.

 

Related Articles:
Parity
TCP/IP Addresses
Calculating Subnet Masks
Cisco ACLs

Top Articles:
Windows 2000/XP
    Commands
Unattended Installations
Subnet Masks
Cisco Access Lists
Network Wiring