Converting Binary IP Addresses to Decimal
Routers, being computers, work in binary. For example, 32-bit IPv4 addresses are used throughout the Internet, so you need to understand how to work with IP addresses. Because people usually like to work in decimal, IP addresses are typically written in a format called
dotted
decimal notation
. The 32 bits in the address are divided into four 8-bit chunksthese
chunks
are called
octets
. Each octet is converted into decimal and then separated by dots.
When converting a binary octet to decimal, each binary digit is weighted based on its position, as described earlier. The weights for the eight bit
positions
in an octet are shown in Figure C-2.
For example, consider the following IP address, written in binary:
10101100000100001000001100001100
Follow these steps to write this binary address in dotted decimal notation:
|
Step 1.
|
Divide the 32 bits into four octets, as
follows
:
10101100 00010000 10000011 00001100
|
|
Step 2.
|
Convert the first octet into decimal, as
illustrated
in Figure C-3.
Note the following points in Figure C-3:
-
The least significant digit, 0, has a weight of 2
; thus, it represents 0 * 2
= 0 * 1 = 0.
-
The
next
digit, also 0, has a weight of 2
1
; thus, it represents 0 x* 2
1
= 0 * 2 = 0.
-
The next digit, 1, has a weight of 2
2
; thus, it represents 1 * 2
2
= 1 * 4 = 4. The weighted value for each of the other digits is calculated in the same way.
-
The most significant digit (on the far left), 1, has a weight of 2
7
; thus, it represents 1 * 2
7
= 1 * 128 = 128.
-
Therefore, the binary number 10101100 in decimal is the sum of each of these representations: 128 + 0 + 32 + 0 + 8 + 4 + 0 + 0 = 172.
|
|
Step 3.
|
Repeat this process for the other three octets. The results are as follows:
-
00010000 binary equals 16 decimal.
-
10000011 binary equals 131 decimal.
-
00001100 binary equals 12 decimal.
|
Note
You can confirm these results using the
decimal-to-binary
conversion chart in Table C-1.
Thus, the IP address 10101100000100001000001100001100 in dotted decimal notation is 172.16.131.12.
|