# A Guide To Network Math You are probably accustomed to using what is called decimal- the numbering system you’ve been learning since kindergarten. In networking we use three primary numbering systems: binary, decimal, and hexadecimal. It is direly important to know what each numbering system is for, and more specifically how to convert from one system to another. But don’t worry; it’s easier than you might think.

### An Introduction to Binary

Binary is short for binary digit. If you know your prefixes well, you know that bi simply means two. The best part of binary is that it only has two numbers in it: one and zero. This is what we call machine code, since it is the language that powers most hardware and computers.

The premise of binary is simple: we arrange 1’s and 0’s in a row to make any number we please. Each one or zero is called a bit, and are commonly arranged in groups of 4 (called a nibble) or 8 (called a byte). So why use 1’s and 0’s instead of real numbers? The answer is simple: computers are dumb devices. To understand and process data, they use electrical signals. A binary 1 (usually) indicates that there is a high voltage level, and a binary 0 (usually) indicates a low voltage level. This is how computers can send and receive data- although however crude it may be.
Thus, the thought is burning in your mind: how do you make a decimal equivalent of 45 with 1’s and 0’s? Binary works on a rather different numbering system than you are probably used to. Each position in a byte corresponds to a number. If you haven’t noticed, each position in a byte is double the value of the position before it. This way, we can make any number up to 255 with each byte. If you wanted to know the function to find the value in decimal, with the given position in the byte, you can use 2^n (where n is the position). Note that the position count starts with zero. So if the position was the second right hand number, the equation would be 2^1.

To get 45 in particular, we need to review one last concept. Consider each 0 as a “no” and each 1 as a “yes.” For every binary 1 (or yes) you get, you write down the corresponding decimal number. For each binary 0 (or no) you get, you don’t write down anything. Now add up all the decimal numbers you got, and you have the decimal equivalent of a binary number. When you are instead converting a decimal number to binary, it is generally quickest to ask “What’s the biggest number I could take out of 101?” In our case, it is 64. So likewise, we start with 64 and continue our way down with “What’s the biggest number I can take out of 37? (101 – 64)” This is done until the number required is obtained. For every decimal number we wrote down, we consider its position a binary 1. If the number wasn’t used, we consider the position a binary 0. Keep in mind that Cisco makes a note of describing a byte as a single addressable data storage location. And by all means, this is completely true- expect to see it on Cisco exams.
Now that you know how to convert decimal to binary (and binary to decimal), we can move on to the wonderful world of hexadecimal!

Whereas decimal is a base 10 numbering system (since it has 10 total numbers 0-9), and binary is base 2, hexadecimal is base 16. But, you might ask, how is it possible if there are only 10 numbers? Easy- we use letters A through F to make up for the 7 missing numbers.

Remember how we used bytes to work with binary and decimal numbers? This time around we will use nibbles when working with hexadecimal. The numbering scheme is actually quite easy once you get the hang of it. To convert a hexadecimal value to binary, remember that we are dealing with nibbles, not bytes. Each number (or letter) corresponds to a nibble. Therefore, the hexadecimal number AF converts to a 10 and a 15. The result, in binary, would be 1010 1111 (consult the diagram above).Now we can finally convert the byte into a decimal number. When we add all the digits up, the binary number 10101111 becomes 175 in decimal. Note that since hexadecimal numbers can easily be confused with decimal numbers, you will more than likely see a 0x before a hex number. In our previous example, it would be 0xAF. If we want to instead convert a binary number into hexadecimal, we do the opposite. Break the byte into two nibbles, and then find the value of each nibble. Convert the value of each nibble into hexadecimal, and you get your final result. The binary number 1111 0001, for instance, would be the equivalent of F1 in hex (or otherwise known as 0xF1). Then of course, we could add the binary digits up and get 241 for the decimal equivalent. Now, you’re probably thinking, “When will I ever use hexadecimal? I’ve never heard of it before!” Chances are, you’ve already come into contact with it. HTML and CSS both use hexadecimal numbers for color codes. The network interface card you are using to view this webpage right now has a physical address coded in hexadecimal. And if you have a funny bone, there are some clever jokes associated with hexadecimal. Can you see the logical flaw in the diagram below? Most mathematicians would say a zero multiplied by anything is zero. That’s true, but the deception here is that it isn’t a zero at all! It’s actually the beginning of the hex value of 12, which is the equivalent of 18 in decimal.
And if you were wondering if there were any binary jokes, rejoice. The phrase “There are only 10 kinds of people in the world; those who understand binary and those who don’t” confuses the reader with a decimal 10, only it is actually a binary 2. Clever, isn’t it?

1. Mike March 19, 2009