Rabu, 25 Oktober 2017

178 - 2

Decimal-to-Binary Conversions

Not only do you need to be able to convert binary to decimal, but you also need to be able to convert decimal to binary. You often need to examine an individual octet of an address given in dotted decimal notation. Such is the case when the network bits and host bits divide an octet.

As an example, if a host with the address 172.16.4.20 were using 28 bits for the network address, the first 4 bits of the last octet would be network address bits and the last 4 bits would be host bits. To discover that this host is on the network 172.16.4.16, you would need to examine the last octet in binary. This process of extracting the network address from a host address will be explained in the section “IPv4 Addresses for Different Purposes,” later in this chapter.

To begin the conversion process, you start by determining whether the decimal number of an octet is equal to or greater than the largest decimal value represented by the most signifi-cant bit. Because the representation of addresses is limited to decimal values for a single octet, you examine only the process of converting 8-bit binary to the decimal values of 0 to 255 in this section. In the highest position, you determine whether the value is equal to or greater than 128. If the value is smaller than 128, you place a 0 in the 128-bit position and move to the 64-bit position.
If the value in the 128-bit position is larger than or equal to 128, place a 1 in the 128 posi-tion and subtract 128 from the number being converted. You then compare the remainder of this operation to the next smaller value, 64. You continue this process for all the remaining bit positions: 32, 16, 8, 4, 2, and 1. Figure 6-1 demonstrates the steps using the conversion of 172 to 10101100.

Figure 6-1       Decimal-to-Binary Conversion Steps



172 > 128 ?


Yes



No


Put 1 in Position 128

10000000

172 – 128 = 44

No          Put 0 in Position 64

10000000

Yes

No

Yes

Put 1 in Position 32

10100000

44 – 32 = 12

No          Put 0 in Position 16

10100000

Yes

No

Yes

Put 1 in Position 8

10101000

12 – 8 = 4




No

Yes     Put 1 in Position 4

10101100

4 – 4 = 0

Put 0s in Remaining Positions

STOP

Tidak ada komentar:

Posting Komentar