# How to Convert Between Number Systems: decimal, binary, hexadecimal and IPs

This appendix provides information concerning the following topics:

Now that we have covered how to count (in Appendix A), we need to be able to convert between the three different number systems. This is another skill that takes time and practice to become comfortable using, and it is a skill that can quickly be lost without usage.

Remember that in the binary number system, we use 2 as our base number, giving us a chart that looks like this:

Tip

Re-create this chart right before taking an exam. It is quick to write out on a piece of paper (or the erasable board you get in a vendor exam) and will help you with your addition. I have seen many students lose marks because of simple addition errors.

Each of these numbers represents a bit that has been turned on; that is, represented by a 1 in a bit pattern. So, to convert a decimal number to binary, you must add up these numbers to equal the decimal number—those numbers are then turned on and converted to 1 in the pattern:

In IPv4, we use 32 bits to represent an IP address. These 32 bits are broken down into four groups of 8 bits. Each group is called an octet. You should become very comfortable with working with octets and being able to convert decimal into octets and vice versa. When working with octets, it is customary to insert leading 0s in their placeholders so that all positions in the octet are represented:

Some numbers are used over and over again in IPv4 addresses, so these conversions will be easy to remember:

When converting binary numbers to decimal, we need to use the base-2 chart just like when converting decimal to binary:

Tip

Re-create this chart right before taking an exam. It is quick to write out on a piece of paper (or the erasable board you get in a vendor exam) and will help you with your addition. I have seen many students lose marks because of simple addition errors.

Using this chart as our guide, we add up all the numbers that are represented by a 1 in the binary pattern to convert it to a decimal number:

Again, we use leading 0s in order to form octets:

To convert a decimal IP address to binary, we need to take each individual number and convert it to binary:

Tip

When writing out IP addresses in binary, it is customary to put either a space or a period between the octets:

10101100 00010000 01100100 11111110 or 10101100.00010000.01100100.11111110

To convert a binary IP address to decimal, we need to take each individual binary number and convert it to decimal:

In the IPv4 addressing scheme, there are 232 potential unique addresses that are mathematically possible. If we didn’t use the dotted-decimal format of breaking down 32-bit address into four groups of 8 bits, we may have to use numbers like 3,232,238,081 for 192.168.10.1, or 84,215,041 instead of 10.10.10.1. Which would be easier for you to remember?

This is a conversion that you will be using more than converting hex to decimal. It is very simple to do. Each hex digit can be represented by four binary digits using the following table:

Tip

Re-create this chart right before taking an exam. It is quick to write out on a piece of paper (or the erasable board you get in a vendor exam) and will help you with your conversions. I have seen many students lose marks because of simple errors.

When converting hex to binary, it is customary to convert pairs of hex digits to binary octets, as shown in Example 1.

If there is an uneven number of hex digits to make a complete octet, put a leading 0 at the beginning of the hex number, as shown in Example 2.

Note

Leading 0s are used to complete the first octet (DB8 = 0DB8)

This is also a conversion that you will be using more than converting decimal to hex. Using the same table as shown in the preceding section, convert each octet of binary to a pair of hex digits, as shown in Example 3.

If there is an uneven number of binary digits to make a complete octet, put one or more leading 0s at the beginning of the binary number, as shown in Example 4.

Note

Leading 0s are used to complete the first octet (0FF5 = FF5)

Tip

Although it takes an extra step, I find it faster to convert hexadecimal digits to binary and then binary to decimal. I can add and subtract faster than multiplying and dividing by 16s.

Example 5 shows the process for converting an entire IP address from hex to decimal.

IPv4 addresses are not usually represented in hexadecimal; an exception is when you are capturing traffic with software such as Wireshark, which shows all traffic in hex.

Although this type of conversion is not used very often, you should still understand how to convert a decimal number to a hexadecimal number. To do this conversion, you have to use long division while leaving the remainders in integer form—do not use decimal answers!

The steps involved are as follows:

1. Divide the decimal number by 16. Leave the remainder in integer form (no decimals).

Write down the remainder in hexadecimal form.

2. Divide the result from step 1 by 16.

Write down the remainder in hexadecimal form.

3. Repeat this process until you are left with an answer of 0.

If there is a remainder, write that down in hexadecimal form.

4. The hex value is the sequence of remainders from the last one to the first one.

Examples 6, 7, and 8 show how to convert decimal numbers to hexadecimal.

This is also a type of conversion that isn’t used very often. This time we will be multiplying by powers of 16 to convert hexadecimal numbers to decimal.

The steps involved are as follows:

1. Take the last digit (also known as the least significant digit) in the hexadecimal number and multiply it by 160. Put this number off to the side for right now.

Remember that 160 = 1, so you are multiplying this digit by 1.

2. Take the second-to-last digit in the hex number and multiply it by 161. Also put this number off to the side.

You are multiplying this digit by 16.

3. Continue multiplying the digits with increasing powers of 16 until you are finished multiplying all of the individual hexadecimal digits.

4. Add up all of the results from your multiplications and you have your answer in decimal.

Examples 9 through 11 show you how to convert a hexadecimal number to decimal.

The following chart lists the three most common number systems used in networking: decimal, hexadecimal, and binary. Some numbers you will remember quite easily, as you use them a lot in your day-to-day activities. For those other numbers, refer to this chart.

## Вас заинтересует / Intresting for you: 