2 -2 N UMBER C ONVERSIONS

2 -2 N UMBER C ONVERSIONS

In the previous section, you saw how a number of any base can be converted to the familiar decimal system using the sum-of-the-weights method. In this section, we will show you how a decimal number can be converted to binary, octal, or any number system.

To convert a decimal number to its equivalent in any base, you must perform

a series of divisions by the desired base. The conversion process starts by dividing the decimal number by the base. If there is a remainder, it is placed in the least significant digit (right-most) position of the new base number. If there is no remainder, a 0 is placed in least significant digit position. The result of the division is then brought down, and the process is repeated until the final result of the successive divisions is 0. This methodology may be a little cumbersome; however, it is the easiest conversion method to under- stand and employ.

As a generic example, let’s find the base 5 equivalent of the number Z (see Figure 2-5). The first division (Z ÷ 5) gives an N 1 result and a remainder R 1 . The remainder R 1 becomes the first digit of the base 5 number (the least significant digit). To obtain the next base 5 digit, the N 1 result is again divided

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION Introductory Number Systems C HAPTER 1 Concepts

and Codes 2

by 5, giving an N 2 result and an R 2 remainder that becomes the second base 5 digit. This process is repeated until the result of the division (N n ÷ 5) is 0, giving the last remainder R n , which becomes the most significant digit (left- most digit) of the base 5 number.

New base 5 number is ( Rn ... R 4 R 3 R 2 R 1 ) 5

Figure 2-5. Method for converting a decimal number into any base.

Now, let’s convert the decimal number 35 10 to its binary (base 2) equivalent

using this method:

Therefore, the base 2 (binary) equivalent of the decimal number 35 is 100011.

As another exercise, let’s convert the number 1355 10 to its hexadecimal (base

16) equivalent: Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION ntroductory Number Systems C HAPTER 1 Concepts

and Codes 2

Thus, the hexadecimal equivalent of 1355 10 is 54B hex (remember that the hexadecimal system uses the letter B to represent the number 11).

There is another method, which is a little faster, for computing the binary equivalent of a decimal number. This method employs division by eight, instead of by two, to convert the number first to octal and then to binary from octal (three bits at a time).

For instance, let’s take the number 145 10 :

The octal equivalent of 145 10 is 221 8 , so from Table 2-2, we can find that 221 8

equals 010010001 binary:

2 -3 O NE ’ S AND T WO ’ S C OMPLEMENT

The one’s and two’s complements of a binary number are operations used by programmable controllers, as well as computers, to perform internal mathematical calculations. To complement a binary number means to change it to a negative number. This allows the basic arithmetic operations of

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION Introductory Number Systems C HAPTER 1 Concepts

and Codes 2

subtraction, multiplication, and division to be performed through successive addition. For example, to subtract the number 20 from the number 40, first complement 20 to obtain –20, and then perform an addition.

The intention of this section is to introduce the basic concepts of complementing, rather than to provide a thorough analysis of arithmetic operations. For more information on this subject, please use the references listed in the back of this book.