Appendix B. How to Convert Between Number Systems

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.

How to Convert from Decimal to Binary

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

210 29 28 27 26 25 24 23 22 21 20
1 024 512 256 128 64 32 16 8 4 2 1

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:

1200 = 1024 + 128 + 32 + 16 = 10010110000
755 = 512 + 128 + 64 + 32 + 16 + 2 + 1 = 1011110011
500 = 256 + 128 + 64 + 32 + 16 + 4 = 111110100
233 = 128 + 64 + 32 + 8 + 1 = 11101001
187 = 128 + 32 + 16 + 8 + 2 + 1 = 10111011
160 = 128 + 32 = 10100000
95 = 64 + 16 + 8 + 4 + 2 + 1 = 1011111
27 = 16 + 8 + 2 + 1 = 11011

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:

95 = 64 + 16 + 8 + 4 + 2 + 1 = 01011111
27 = 16 + 8 + 2 + 1 = 00011011

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

27 26 25 24 23 22 21 20
Decimal # 128 64 32 16 8 4 2 1 = Binary #
0 = 0 0 0 0 0 0 0 0 = 00000000
1 = 0 0 0 0 0 0 0 1 = 00000001
64 = 0 1 0 0 0 0 0 0 = 01000000
128 = 1 0 0 0 0 0 0 0 = 10000000
192 = 1 1 0 0 0 0 0 0 = 11000000
224 = 1 1 1 0 0 0 0 0 = 11100000
240 = 1 1 1 1 0 0 0 0 = 11110000
248 = 1 1 1 1 1 0 0 0 = 11111000
252 = 1 1 1 1 1 1 0 0 = 11111100
254 = 1 1 1 1 1 1 1 0 = 11111110
255 = 1 1 1 1 1 1 1 1 11111111

How to Convert from Binary to Decimal

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

210 29 28 27 26 25 24 23 22 21 20
1 024 512 256 128 64 32 16 8 4 2 1

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:

101011110000 = 1024 + 256 + 64 + 32 + 16 + 8 = 1400
1011110011 = 512 + 128 + 64 + 32 + 16 + 2 + 1 = 755
111100010 = 256 + 128 + 64 + 32 + 2 = 482
11100100 = 128 + 64 + 32 + 4 = 228
10111010 = 128 + 32 + 16 + 8 + 2 = 186
10101010 = 128 + 32 + 8 + 2 = 170
1001101 = 64 + 8 + 4 + 1 = 77
1101 = 8 + 4 + 1 = 13

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

01001101 = 64 + 8 + 4 + 1 = 77
00001101 = 8 + 4 + 1 = 13

How to Convert from Decimal IP Addresses to Binary and from Binary IP Addresses to Decimal

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

192.168.10.1
192 = 11000000
168 = 10101000
10 = 00001010
1 = 00000001
= 11000000 10101000 00001010 00000001
172.16.100.254
172 = 10101100
16 = 00010000
100 = 01100100
254 = 11111110
= 10101100 00010000 01100100 11111110

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:

11000000 10101000 01100100 11110011
11000000 = 192
10101000 = 168
01100100 = 100
1111011 = 243
= 192.168.100.243
00001010 10010110 01100000 00000001
00001010 = 10
10010110 = 150
01100000 = 96
00000001 = 1
= 10.150.96.1

A Bit of Perspective

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?

How to Convert from Hexadecimal to Binary

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:

Hex Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

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.

Example 1: Convert C9 to Binary

Step 1 C = 1100
Step 2 9 = 1001
Therefore C9 = 11001001

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.

Example 2: Convert DB8 to Binary

Step 1 D = 1101
Step 2 B = 1011
Step 3 8 = 1000
Therefore DB8 = 00001101 10111000

Note

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

How to Convert from Binary to Hexadecimal

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.

Example 3: Convert 11000101 to Hex

Step 1 1100 = C
Step 2 0101 = 5
Therefore 11000101 = C5

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.

Example 4: Convert 111111110101 to Binary

Step 1 1111 = F
Step 2 1111 = F
Step 3 0101 = 5
Step 4 Because there aren’t enough hex digits to make a complete pair, add leading 0s to complete the pair. In this case, add 0000 to the beginning of the number.
Therefore 0000111111110101 = 0F F5

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.

Example 5: Convert the IP Address C0A80101HEX to Decimal

Step 1 C0 = 11000000 = 192
Step 2 A8 = 10101000 = 168
Step 3 01 = 00000001 = 1
Step 4 01 = 00000001 = 1
Therefore C0A80101HEX = 192.168.1.1

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.

How to Convert from Decimal to Hexadecimal

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.

Example 6: Convert 18810 to Hex

Step 1 188 / 16 = 11 with a remainder of 12 12 in hex is C
Step 2 11 / 16 = 0 with a remainder of 11 11 in hex is B
Therefore 18810 = BCHEX

Example 7: Convert 25510 to Hex

Step 1 255 / 16 = 15 with a remainder of 15 15 in hex is F
Step 2 15 / 16 = 0 with a remainder of 15 15 in hex is F
Therefore 25510 = FFHEX

Example 8: Convert 123410 to Hex

Step 1 1234 / 16 = 77 with a remainder of 2 2 in hex is 2
Step 2 77 / 16 = 4 with a remainder of 13 13 in hex is D
Step 3 4 / 16 = 0 with a remainder of 4 4 in hex is 4
Therefore 123410 = 4D2HEX

How to Convert from Hexadecimal to Decimal

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.

Example 9: Convert C3HEX to Decimal

Step 1 3 × 160 = 3 × 1 = 3
Step 2 C × 161 = 12 × 16 = 192
Therefore C3HEX = 195

Example 10: Convert 276HEX to Decimal

Step 1 6 × 160 = 6 × 1 = 6
Step 2 7 × 161 = 7 × 16 = 112
Step 3 2 × 162 = 2 × 256 = 512
Therefore 276HEX = 630

Example 11: Convert FACEHEX to Decimal

Step 1 E × 160 = 14 × 1 = 14
Step 2 C × 161 = 12 × 16 = 192
Step 3 A × 162 = 10 × 256 = 2560
Step 4 F × 163 = 15 × 4096 = 61 440
Therefore FACEHEX = 64 206
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.111.125