Su Chen Jonathon Lin

Programmable Logic Controllers


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

3.4: Binary and decimal numbers

DecimalBinary
00
11
210
311
4100
5101
6110
7111
81000
91001
101010
image

      Figure 3.1: A 2-byte word

      The octal number system uses the number 8 as its base. It has eight unique counting symbols (0, 1, 2, 3, 4, 5, 6, and 7). Table 3.5 shows octal numbering with their decimal and binary equivalents.

      Each digit in an octal number has a place value that is a power of eight raised to n (or 8n), where n is the position, as shown in Table 3.6.

      The octal number 25738 is equivalent to the decimal number 1403 (or 1024 + 320 + 56 + 3). Its conversion is shown below.

image

      We can express 25738 = 140310.

      The octal numbering system uses one digit to represent three binary digits (or bits). In this way, a large binary number can be readily represented by an octal number with much fewer digits (Figure 3.2). As can be seen, that one 15-bit binary number is expressed by a 5-digit octal number.

      Table 3.5: Octal numbering with decimal and binary equivalents

OctalDecimalBinary
000
111
2210
3311
44100
55101
66110
77111
1081000
1191001
12101010
13111011
14121100
15131101
16141110
17151111

      The hexadecimal number system uses the number 16 as its base. It has sixteen unique counting symbols, the numerals 0 – 9 and the letters A – F. Table 3.7 shows hexadecimal numbering with their decimal and binary equivalents.

      Each digit in a hexadecimal number has a place value 16n that is a power of sixteen raised to n, where n is the position as shown in Table 3.8.

      Table 3.6: Place values of octal numbers

image image

      Figure 3.2: An octal number

      The hexadecimal number 23B16 is equivalent to the decimal number 57110 (or 512 + 48 + 11). Its conversion is shown below:

image

      The decimal equivalent of 23B16 = 57110.

      The hexadecimal numbering system uses one digit to represent four binary digits (or bits). In this way, a very large binary number can be concisely represented by a hexadecimal number with very few digits (Figure 3.3). In this example, one 16-bit binary number is expressed by a 4-digit hexadecimal number.

      Table 3.7:: Hexadecimal numbering with decimal and binary equivalents

HexadecimalDecimalBinary
000
111
2210
3311
44100
55101
66110
77111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111

      The same numerical quantity can be expressed in different numbering systems and their expressions are equivalent to each other. To facilitate the number conversions in various numbering systems, numbers need to be expressed with their numbering base. A numerical quantity of 12 is expressed in four number systems as follows:

      1210 = 148 = C16 = 11002

      Table 3.8: Place values of hexadecimal numbers

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