Converting IP Addresses


IP addresses are 32-bit binary numbers, but because humans would find it inconvenient to write down 32-bit numbers, the addresses are written in decimal. The format of decimal IP addresses is often called canonical format, and sometimes called dotted decimal format. For example, the next two lines show the binary version of an IP address, followed by the same IP address written as a dotted decimal number. It's obvious from comparing the two that, given a choice, it's typically much easier to work with the decimal version:

00001000 00000100 00000010 000000001

8.4.2.1

The next two sections cover the conversion process for IP addresses, first from decimal to binary, and then vice versa.

Converting Decimal IP Addresses to Binary IP Addresses

You have already read about the math behind the conversion process between decimal and binary. To convert IP addresses, you simply need to follow a few additional rules:

1.

When converting from a decimal IP address to binary, each of the 4 decimal numbers in the decimal IP address converts to an 8-bit number, giving you a total of 32 bits.

2.

If a decimal number converts to a binary number that has less than 8 digits, put binary 0s in front of the number to create an 8-digit binary number.

3.

The 32-bit binary IP address is formed by simply writing down each of the 4 sets of 8 bits in order.

In other words, to convert a decimal IP address to its 32-bit binary equivalent, you would convert each of the 4 decimal numbers in a decimal IP address to a binary number. You might recall from Chapter 10 that each of the 4 numbers in a decimal IP address, separated by periods, is called an octet. Essentially, you convert each of the 4 decimal octets to 8-bit binary numbers. For any of these binary numbers that converted to less than 8 digits, you would put binary 0s to the left to make them 8 digits long. Finally, just think of the 4 octets as one long 32-bit number, and you're done!

Table B-15 shows a sample conversion of the IP address 100.235.2.2.

Table B-15. Conversion of Decimal IP Address 100.235.2.2 to Binary
 

First Octet

Second Octet

Third Octet

Fourth Octet

Decimal octet

100

235

2

2

Each octet converted to binary (Step 1)

1100100

11101011

10

10

Binary octets, after putting 0s in front (Step 2)

01100100

11101011

00000010

00000010

Resulting 32-bit number (Step 3)

01100100111010110000001000000010


Table B-15 begins with the decimal IP address in the first row, and the results of each of the three conversion steps in the next three rows. The actual math for converting the decimal numbers (Step 1) is not shown, but you can refer to the previous section for examples using decimal 100 and 235. For the first, third, and fourth octets, the converted binary numbers are less than 8 bits long, so at Step 2, binary 0s were added to the left to make them all 8 bits long. Step 3 just lists all 32 bits in succession. In real life, there's no need to actually write down Step 3; you can just see the 4 sets of 8 bits all in a row and think of it as a 32-bit number.

Converting Binary IP Addresses to Decimal IP Addresses

To convert from a binary IP address to its decimal equivalent, you already know the 32-bit IP address. The process is rather simple compared to converting from decimal to binary:

Step 1.

Separate the 32 bits into 4 groups of 8 bits (4 octets).

Step 2.

Convert each binary octet to decimal.

Step 3.

Put a period between the four decimal numbers.

The algorithm can be shown with a sample binary value01100100111010110000000100000001. Table B-16 organizes the bits into octets with 8 bits each.

Table B-16. Conversion of Binary IP Address to Decimal
 

First Octet

Second Octet

Third Octet

Fourth Octet

Binary value, separated into 4 octets (Step 1)

01100100

11101011

00000001

00000001

Each octet converted to decimal (Step 2)

100

235

1

1

Decimal IP address in dotted decimal format (Step 3)

100.235.1.1


The resulting IP address, with the periods added, would be 100.235.1.1. The math used for the conversion was covered in the section titled "Converting from Binary to Decimal" earlier in this appendix. But the conversion process is not the tricky part. When you start with a 32-bit number, as long as you organize it into 4 sets of 8 bits (4 binary octets), you can go through the math to convert each 8-bit binary to decimal. However, if you misstep and convert a 9-bit binary to decimal and then a 7-bit binary number to decimal, you'll be converting the number incorrectly.

Using a Conversion Chart

Now you understand the basics of how decimal and binary work and how to convert between the two. You also know a few rules you must follow when converting IP addresses between the two formats.

You can always use a calculator to do the math of converting a decimal number to binary, or vice versa. Because IP addresses only use decimal numbers between 0 and 255, you can also use a binary/decimal conversion chart. A binary/decimal conversion chart simply lists decimal numbers along with their binary equivalents. That way, you can look in the chart and find the numbers without using all the math covered earlier in this appendix.

For instance, to convert 100.235.1.1 to binary, you could look in the chart and find the decimal number 100. Beside it, you would find the 8-bit binary number 01100100. You would simply write those digits down as the first 8 binary digits. Next, you would find 235 in the chart, find the binary value beside itnamely 11101011and write that down.

You can also use the chart to convert from binary IP addresses to decimal. You follow the same algorithm, but instead of doing the math, you find the 8-bit binary number in the chart and record the decimal number beside it as the value of the IP address in that octet.

Table B-17 lists a binary/decimal conversion chart for your reference. Note that all the binary numbers are shown as 8-digit numbers, because when they're used for converting IP addresses, you will want a full 8 bits for each octet.

Table B-17. Binary/Decimal Conversion Chart

Decimal Value

Binary Value

Decimal Value

Binary Value

0

0000 0000

23

0001 0111

1

0000 0001

24

0001 1000

2

0000 0010

25

0001 1001

3

0000 0011

26

0001 1010

4

0000 0100

27

0001 1011

5

0000 0101

28

0001 1100

6

0000 0110

29

0001 1101

7

0000 0111

30

0001 1110

8

0000 1000

31

0001 1111

9

0000 1001

32

0010 0000

10

0000 1010

33

0010 0001

11

0000 1011

34

0010 0010

12

0000 1100

35

0010 0011

13

0000 1101

36

0010 0100

14

0000 1110

37

0010 0101

15

0000 1111

38

0010 0110

16

0001 0000

39

0010 0111

17

0001 0001

40

0010 1000

18

0001 0010

41

0010 1001

19

0001 0011

42

0010 1010

20

0001 0100

43

0010 1011

21

0001 0101

44

0010 1100

22

0001 0110

45

0010 1101

46

0010 1110

70

0100 0110

47

0010 1111

71

0100 0111

48

0011 0000

72

0100 1000

49

0011 0001

73

0100 1001

50

0011 0010

74

0100 1010

51

0011 0011

75

0100 1011

52

0011 0100

76

0100 1100

53

0011 0101

77

0100 1101

54

0011 0110

78

0100 1110

55

0011 0111

79

0100 1111

56

0011 1000

80

0101 0000

57

0011 1001

81

0101 0001

58

0011 1010

82

0101 0010

59

0011 1011

83

0101 0011

60

0011 1100

84

0101 0100

61

0011 1101

85

0101 0101

62

0011 1110

86

0101 0110

63

0011 1111

87

0101 0111

64

0100 0000

88

0101 1000

65

0100 0001

89

0101 1001

66

0100 0010

90

0101 1010

67

0100 0011

91

0101 1011

68

0100 0100

92

0101 1100

69

0100 0101

93

0101 1101

94

0101 1110

118

0111 0110

95

0101 1111

119

0111 0111

96

0110 0000

120

0111 1000

97

0110 0001

121

0111 1001

98

0110 0010

122

0111 1010

99

0110 0011

123

0111 1011

100

0110 0100

124

0111 1100

101

0110 0101

125

0111 1101

102

0110 0110

126

0111 1110

103

0110 0111

127

0111 1111

104

0110 1000

128

1000 0000

105

0110 1001

129

1000 0001

106

0110 1010

130

1000 0010

107

0110 1011

131

1000 0011

108

0110 1100

132

1000 0100

109

0110 1101

133

1000 0101

110

0110 1110

134

1000 0110

111

0110 1111

135

1000 0111

112

0111 0000

136

1000 1000

113

0111 0001

137

1000 1001

114

0111 0010

138

1000 1010

115

0111 0011

139

1000 1011

116

0111 0100

140

1000 1100

117

0111 0101

141

1000 1101

142

1000 1110

166

1010 0110

143

1000 1111

167

1010 0111

144

1001 0000

168

1010 1000

145

1001 0001

169

1010 1001

146

1001 0010

170

1010 1010

147

1001 0011

171

1010 1011

148

1001 0100

172

1010 1100

149

1001 0101

173

1010 1101

150

1001 0110

174

1010 1110

151

1001 0111

175

1010 1111

152

1001 1000

176

1011 0000

153

1001 1001

177

1011 0001

154

1001 1010

178

1011 0010

155

1001 1011

179

1011 0011

156

1001 1100

180

1011 0100

157

1001 1101

181

1011 0101

158

1001 1110

182

1011 0110

159

1001 1111

183

1011 0111

160

1010 0000

184

1011 1000

161

1010 0001

185

1011 1001

162

1010 0010

186

1011 1010

163

1010 0011

187

1011 1011

164

1010 0100

188

1011 1100

165

1010 0101

189

1011 1101

190

1011 1110

214

1101 0110

191

1011 1111

215

1101 0111

192

1100 0000

216

1101 1000

193

1100 0001

217

1101 1001

194

1100 0010

218

1101 1010

195

1100 0011

219

1101 1011

196

1100 0100

220

1101 1100

197

1100 0101

221

1101 1101

198

1100 0110

222

1101 1110

199

1100 0111

223

1101 1111

200

1100 1000

224

1110 0000

201

1100 1001

225

1110 0001

202

1100 1010

226

1110 0010

203

1100 1011

227

1110 0011

204

1100 1100

228

1110 0100

205

1100 1101

229

1110 0101

206

1100 1110

230

1110 0110

207

1100 1111

231

1110 0111

208

1101 0000

232

1110 1000

209

1101 0001

233

1110 1001

210

1101 0010

234

1110 1010

211

1101 0011

235

1110 1011

212

1101 0100

236

1110 1100

213

1101 0101

237

1110 1101

238

1110 1110

247

1111 0111

239

1110 1111

248

1111 1000

240

1111 0000

249

1111 1001

241

1111 0001

250

1111 1010

242

1111 0010

251

1111 1011

243

1111 0011

252

1111 1100

244

1111 0100

253

1111 1101

245

1111 0101

254

1111 1110

246

1111 0110

255

1111 1111





Computer Networking first-step
Computer Networking First-Step
ISBN: 1587201011
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Wendell Odom

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net