Programmable Logic Controllers. Su Chen Jonathon Lin

Чтение книги онлайн.

Читать онлайн книгу Programmable Logic Controllers - Su Chen Jonathon Lin страница 16

Автор:
Жанр:
Серия:
Издательство:
Programmable Logic Controllers - Su Chen Jonathon Lin

Скачать книгу

alt="image"/> image

      Figure 3.3: A hexadecimal number

      The focus of this section is to show the techniques of converting a numerical quantity from one number system to another. A decimal number can be converted to binary, octal, and hexadecimal. Converting a decimal number to its equivalent in another number system involves the process of dividing the decimal number by the base number of the system from which the conversion is made. The conversion to binary involves division by 2, conversion to octal involves division by 8, and conversion to hexadecimal involves division by 16. The generic procedure involves:

       a.Dividing the decimal number by the base number.

      Decimal number ÷ Base number = Quotient (Q1) + Remainder (R1)

      Quotient (Q1) ÷ Base number = Quotient (Q2) + Remainder (R2)

      Quotient (Q2) ÷ Base number = Quotient (Q3) + Remainder (R3)

      Quotient (Qn-1) ÷ Base number = Quotient (Qn) + Remainder (Rn)

      Repeat the process until the quotient of the division becomes 0.

       b.Arranging the remainders in proper sequence to express the number in the new number system.

      Use the following tips to express the number in the new number system:

      •The remainder (R1) is placed in the least significant digit (LSD, right-most) position of the new base number.

      •The remainder (R2) is placed in the second position from the right of the new base number.

      •The last remainder (Rn) is the most significant digit (MSD, left-most digit) of the new base number.

      The new base number is expressed as (Rn… R3R2R1)base number

      This procedure can be applied to converting decimal numbers to all three other number systems: binary, octal, and hexadecimal.

       3.6.1Converting Decimal to Binary

      Converting a decimal number to its binary equivalent involves repeatedly dividing the decimal number by 2 until a quotient of 0 is obtained. Each remainder obtained is a digit of the equivalent binary number, starting from right to left.

       Example 3.1: Converting decimal 125 to its binary equivalent

      The procedure of converting 12510 to its binary equivalent is outlined below. The binary equivalent of 12510 becomes 11111012.

DivisionQuotientRemainder
125 ÷ 2621 (LSD)
62 ÷ 2310
31 ÷ 2151
15 ÷ 271
7 ÷ 231
3 ÷ 211
1 ÷ 201 (MSD)

       Example 3.2: Converting decimal 70 to its binary equivalent

      The procedure of converting 7010 to the binary number is listed below. The binary equivalent of 7010 becomes 10001102.

DivisionQuotientRemainder
70 ÷ 2350 (LSD)
35 ÷ 2171
17 ÷ 281
8 ÷ 240
4 ÷ 220
2 ÷ 210
1 ÷ 201 (MSD)

       3.6.2Converting Decimal to Octal

      Converting a decimal number to its octal equivalent involves repeatedly dividing the decimal number by 8 until a quotient of 0 is obtained. Each remainder obtained is a digit of the equivalent binary number, starting from right to left.

       Example 3.3: Converting decimal 253 to its octal equivalent

      The procedure of converting 25310 to octal number is as follows:

DivisionQuotientRemainder
253 ÷ 8315 (LSD)
31 ÷ 837
3 ÷ 803 (MSD)

      The octal equivalent of 25310 is 3758.

       3.6.3Converting Decimal to Hexadecimal

      Converting a decimal number to its hexadecimal equivalent involves repeatedly dividing the decimal number by 16 until a quotient of 0 is reached. Each remainder obtained is a digit of the equivalent hexadecimal number, starting from right to left.

       Example 3.4: Converting decimal 895 to its hexadecimal equivalent

      The procedure of converting 89510 to hexadecimal number is as follows:

DivisionQuotientRemainder
895 ÷ 165515 (F) (LSD)
55 ÷ 1637
3 ÷ 1603 (MSD)

      The hexadecimal equivalent of 89510 becomes 37F16.

       3.6.4Converting Binary to Decimal

      The procedure of converting a binary number to its decimal equivalent starts by multiplying the place values to their corresponding digits and summing the results. The procedure of converting binary number 11012 to decimal follows. We can see that 11012 = 1310.

image

       Example 3.5: Converting 110112 to its decimal equivalent

      The decimal equivalent of 110112 is found as follows:

      110112 = 1x24 + 1x23 + 0x22 + 1x21 + 1x20 = 16 + 8 + 0 + 2 + 1 = 2710

       3.6.5Converting Octal to Decimal

      The procedure of converting an octal number to its decimal equivalent starts with multiplying the place values (1, 81, 82,…, 8n) by their corresponding digits and summing the results. An example of converting octal number 5348 to its decimal equivalent follows.

image

       Example 3.6: Converting 6278 to its decimal equivalent

      The decimal equivalent of 6278 is:

image

      

Скачать книгу