A course in TCP/IP networking

Part 1: Numerical bases

 

http://www.cut-the-knot.org/binary.shtml

 

Computer networks using the TCP/IP protocols are the basis of the Internet and therefore of modern advances in communications and commerce. For this reason, working knowledgably with computers now requires understanding the TCP/IP protocols and how networks and subnets are organized. The main TCP/IP network protocol - the IP address - is based on mathematical groupings of 32 bits divided into network and host portions of the address. The network portion of the IP address allows packets of information to be delivered to networks, which are groups of computers connected together and able to communicate directly to each other; the host portion of the IP address allows those packets to be recognized by the correct destination system.

 

The mathematics of networking is very simple, but translating that simplicity into a form humans can understand and work with adds considerably to its complexity. This course covers practical TCP/IP networking and provides exercises in the basic mathematics required to understand networking. This first part of the course discusses numerical bases.

 

Numerical Bases - An Introduction

 

Historically, most simple societies counted using base 5, as did agrarian Western society up to the early years of the 20th century, because base 5 works extremely well with simple human life and with human perception. Base 5 counts in ones up to five ones, at which point those five ones are recounted as one group called a “hand.” Once a “hand” is reached, counting resumes at one hand and one. Using the left hand to keep track of “hands” and the right hand to keep track of ones, in base 5 it is possible to count to 30 on the fingers using only two human hands.

 

Modern Western society counts in base 10, the familiar base learned in school and used in most, but not all, transactions requiring numbers. We also use base 12, base 20 and base 60 in everyday life.  Like all numerical bases, base 10 has advantages and disadvantages. It works moderately well with human perception and very well for written commercial and scientific applications. It does not work well with computers.

 

Computers count best in base two or “binary” because a bit in a computer has two possible states: on and off. The off state represents zero, while the on state represents one. A computer uses numerals in base 10 only when a user interface has been written for base 10 numbers. The computer itself will translate any base 10 input into base 2. 

 

Numerals written in base 2 are difficult for humans to perceive and remember, so IP addresses, like most numbers in computing, are written in base 10. Human perceptual needs are the only reason that this is done.  The need to translate between base 2 and base 10 in networking make it much more complex than it would otherwise be. There is no technical reason that network numbers must be translated between base 10 and 2. It is entirely psychological.

 

Values in binary can often be cleanly expressed in base 16, also called “hexadecimal” or just “hex.”  Hexadecimal counts in singles up to 16, after which a group of 16 is tallied. The numerals written as 10, 11, 12, 13, 14 and 15 in base 10 are represented instead by a, b, c, d, e and f.

 

Writing numerals

 

When numerals in a basis are written, columns are used instead of fingers to keep track of groups. In base 10 the value of “three hundred-fifty-eight” is written as:

 

100

10

1

3

5

8

 

358 indicates that the number includes eight singles, five groups of ten and three tens of tens or “hundreds.” Another way to think of the columns is as powers of the base. The first column is the basis raised to the power zero, which is always 1. The second column is the base raised to the power one, which is always equal to the basis. The third column is the base raised to the power two, and so on. The numeral 358 can therefore also be thought of as:

 

102

101

100

3

5

8

 

 

This methodology works for all other bases as well. The numeral in base five that includes four groups of twenty-five, three groups of five, and three singles is written as:

 

52

51

50

4

3

3

 

Writing numerals in base 2 is similar, although the places increase quickly, since each column can have only two values, 0 and 1. In base 2 counting proceeds (base two numerals followed by base 10 equivalents):

 

0(0), 1(1), 10(2), 11 (3), 100 (4), 101 (5), 110 (6), 111 (7), 1000 (8) …

 

We usually deal with eight places in binary, since a byte in a computer consists of eight bits. These eight bits have following decimal values:

 

27

26

25

24

23

22

21

20

128

64

32

16

8

4

2

1

 

 

When a numeral is written in a base other than base 10, the basis of the numeral is indicated by a subscript on the right side of the numeral. Thus the value written as 6 in base 10 may also be written as follows:

 

a. 1102                         b. 106               c. 612  (or “one half dozen”)    d. 616  

 

Values in base 16 (hexadecimal) may also be indicated by preceding the value with 0x (zero x).

 

616  = 0x6

 

Translating from base 10 to another base:

 

The following example illustrates translating the value 230 from base 10 to base 5:

 

1. Establish the base 10 value of base 5 groups:

 

50 = 1                      51 = 5                      52 = 25                   53 = 125

 

2. Determine the largest group in the original number.

 

The largest group that can be taken out of 230 is 125.

 

3. Determine how many of the largest group can be taken out of the original number by dividing the original number by the value of the largest group in base 10:

 

230 ÷ 125 = 1 remainder of 105

 

There is one 53 in 230. The value of the 53 column is therefore 1.

 

Repeat the process with the remainder:

 

105 ÷ 25 = 4 remainder 5

 

The value of the 52 column is 4.

 

5 ÷ 5 = 1 remainder 0

 

The value of the 51 column is 1

The value of the 50 column is 0

 

Write out the complete numeral with appropriate subscripting to show the basis:

 

230 = 14105

 

Translating from another base to base 10:

 

The following example translates 111110012 to base 10:

 

1. Establish the base 10 value of the groups in the new base:

 

27

26

25

24

23

22

21

20

128

64

32

16

8

4

2

1

 

2. Multiply each digit in the original number by its base 10 value and add:

 

128 x 1 + 64 x 1 + 32 x 1 + 16 x 1 + 8 x 1 + 0 x 4 + 0 x 2 + 1 x 1 =

128 + 64 + 32 + 16 + 8 + 1 = 249

 

Translating from a base other than 10 to a base other than 10:

 

You will usually have to translate the number into base 10 then into the new base using the methods outlined above. The easiest non-decimal translations are between base 2 (binary) and base 16 (hexadecimal) which require almost no conversion to decimal. These two bases are very closely related because base 16 is simply base 2 raised to the fourth power. This is evident when the groups are written with their values in base 10:

 

Binary

 

28

27

26

25

24

23

22

21

20

256

128

64

32

16

8

4

2

1

 

 

 

 

 

 

 

 

 

Hexadecimal

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

162

 

 

 

161

 

 

 

160

256

 

 

 

16

 

 

 

1

 

To translate from binary into hex, add the decimal values of the last four places of the binary number, translate into hex, and put the result in the one’s place of the hexadecimal number:

 

1011110112 = ___16

 

1 x 8 + 0 x 4 + 1 x 2 + 1 x 1 = 8 + 2 + 1 = 11 = b16

 

Multiply 1 by the value of the 24 column, 2 by the value of the 25 column, 4 by the value of the 26 column, and 8 by the value of the 27 column, add the results and translate into hex. This is the value of the 16’s place in the hexadecimal numeral.

 

1 x 1 + 1 x 2 + 1 x 4 + 0 x 8 = 1 + 2 + 4 = 716

 

Multiply 1 by the value of the 28 column, 2 by the value of the 29 column, 4 by the value of the 210 column, and 8 by the value of the 211  column add the results and translate into hex. This is the value of the 162 place in the hexadecimal numeral.

 

1 x 1 = 116

 

The final result: 1011110112 = 17b16

 

Practice translating between bases:

 

Binary

 

28

27

26

25

24

23

22

21

20

256

128

64

32

16

8

4

2

1

 

 

 

 

 

 

 

 

 

Hexadecimal

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

162

 

 

 

161

 

 

 

160

256

 

 

 

16

 

 

 

1

 

1. Solve the following problems:

 

a. 111111112  = _____________10

b. 111111102  = _____________10

c. 101111112  = _____________10

d. 101110112  = _____________10

 

2. Solve the following problems:

 

a. 14610 = ____________2

b. 19210 = ____________2

c. 22410 = ____________2

d. 19210 = ____________2

 

3. Solve the following problems:

 

a. 25510 = ____16

b. 1510   = ____16

c. 17510 = ____16

d. 24810 = ____16

 

4. Solve the following problems:

 

a. 111111102 = ____16

b. ae16 = ____2

c. 110110002 = ____16

d. f16 = ____2

 

 

Solutions:

 

1. Solve the following problems:

 

a. 111111112  = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 25510

b. 111111102  = 128 + 64 + 32 + 16 + 8 + 4 + 2  = 25410

c. 11111112    =  64 + 32 + 16 + 8 + 4 + 2 + 1 = 12710

d. 101110002  = 128 + 32 + 16 + 8  = 18410

 

2. Solve the following problems:

 

a. 14610 = 146 - 128 = 18 - 16 = 2 - 1 = 0 = 100100102

b. 19210 = 192 - 128 = 64 - 64 = 0 = 110000002

c. 22410 = 224 - 128 = 96 - 64 = 32 - 32 = 0 = 111000002

d. 13110 = 131-128 = 3 -2 = 1 -1 = 0 = 100000112

 

 

3. Solve the following problems:

 

a. 25510 = 255 ÷16 = 15 remainder 15 = ff16

b. 1510 = f16

c. 17510 = 175 ÷ 16 = 10 remainder 15 = af16

d. 24810 = 248 ÷ 16 = 15 remainder 8 = f816

 

4. Solve the following problems:

a. 111111102 = 1 x 8(16s) + 1 x 4 (16s) = 1 x 2(16s) + 1 x 1(16s) = 15 (16s): 8 + 4 + 2 = 14 (1s) = fe16

b. ae16 = 10 (16s) - 8(16s) - 2 (16s): 14 (1s) - 8 = 6 (1s) - 4 = 2(1s) - 2 = 0 = 10101110 2

c. 110110002 = 1 x 8(16s) + 1 x 4 (16s) = 0 x 2(16s) + 1 x 1(16s) = 13 (16s):8 = d816

d. f16 = 8+4+2+1 = 11112

 

Hosted by www.Geocities.ws

1