CompTIA Network+ Certification Guide
上QQ阅读APP看书,第一时间看更新

Converting binary into decimal

Let's take a further look into the orientation of the IPv4 address, with its binary format as well. Since an IPv4 address is 32-bits in length with four octets, the following is an example of an IPv4 address in the binary notation:

11000000.10101000.00000001.10000001

We have been presented with a binary number, so the challenge now is converting binary into decimal. To better understand how the conversion process works, we must first understand the purpose of a base system or radix in mathematics. The radix (base) is a unique number that's used in a positioning system. Since binary is base 2, the radix is 2. Using the positioning system, the first position value (starting from the right) is 0.

In basic mathematics, A0 = 1. This can be further expressed as A x 0 = 1. To further express the remaining positions with the radix of 2, we get the following:

20 = 2 x 0 = 1
21 = 2 x 1 = 2
22 = 2 x 2 = 4
23 = 2 x 2 x 2 = 8
24 = 2 x 2 x 2 x 2 = 16
25 = 2 x 2 x 2 x 2 x 2 = 32
26 = 2 x 2 x 2 x 2 x 2 x 2 = 64
27 = 2 x 2 x 2 x 2 x 2 x 2 x 2 = 128

From the preceding expressions, the following table can be used to assist with calculating base (radix) 2 with its positioning values:

Why did we use the range from 0 to 7 as our positioning values? We need to remember that the number zero (0) is the first of the natural numbers and an integer on the numerical table, and hence the reason we started with 20 as our first position. Another highlight regarding the table is that the last position is 27. This position represents the eighth position on the table. As mentioned earlier in this chapter, there are 8-bits in an octet; whenever we are converting an IP address from binary to decimal notation, we must convert one octet at a time. This means that each bit in an octet is also positioned on the table as well.

To further express a bit that is in the ON state, we use a one. Combining this information with the positioning system, we get the following expressions:

20 = 00000001
21 = 00000010
22 = 00000100
23 = 00001000
24 = 00010000
25 = 00100000
26 = 01000000
27 = 10000000

Let's use an example by representing 27 in the table:

We know from the previous expressions that 27 = 2 x 2 x 2 x 2 x 2 x 2 x 2 = 128. As we can see from the previous table, the bit in the column that has the radix of 27 is turned ON with a 1 in the third row. What if we wanted to represent an entire binary octet such as 10101000? This can simply be substituted in the binary row of the table:

Since we substituted the binary number into our time, let's add the columns that are ON (those that contain the 1s):

27 + 25 + 23 = 168

A further breakdown is as follows:

128 + 32 + 8 = 168

We can conclude from this example that the binary equivalent of 10101000 to decimal is 168. To get an even a better understanding, some practice is recommended. Let's convert the following binary numbers into decimal notation:

  • Converting 11100101 to decimal:

128 + 64 + 32 + 4 + 1 = 229

  • Converting 10000100 to decimal:

128 + 4 = 132

  • Converting 11111111 to decimal:

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

  • Converting 01010101 to decimal:

64 + 16 + 4 + 1 = 85

  • Converting 10101010 to decimal:

128 + 32 + 8 + 2 = 170