Page 76 - Programmable Logic Controllers, Fifth Edition - Mobile version
P. 76

In the result, if the carry is a 1, then the result is positive;
                                                                           The process for dividing one binary number by an-
                   if the carry is a 0, then the result is negative and requires   other is the same for both binary and decimal numbers, as
                   a minus sign.                                         shown in the following example.
                                                                         Decimal      Equivalent binary
                    EXAMPLE 10-4                                               7               111
                                                                                             _
                                                                             _
                                                                           2  q14         10q1110
                    Subtract 101 from 111.
                                                                                             10
                                 111                                                          11
                            + − 011   The 2’s complement                                      10
                                1010  The first 1 indicates that                               10
                                      the result is positive, so it                            10
                                      is disregarded:                                           00
                                      010                                  The basic function of a comparator is to compare the
                                                                         relative magnitude of two quantities. PLC data compari-
                                                                         son instructions are used to compare the data stored in
                                                                         two words (or registers). At times, devices may need to
                    EXAMPLE 10-5                                         be controlled when they are less than, equal to, or greater
                                                                         than other data values or set points used in the applica-
                    Subtract 11011 from 01101.
                                                                         tion, such as timer and counter values. The basic compare
                              01101                                      instructions are as follows:
                         + − 00101    The 2’s complement                                  A = B (A equals B)
                              10010   There is no carry, so the result is             A > B (A is greater than B)
                                      negative; therefore a 1 has to be
                                      subtracted and the 1’s complement                 A < B (A is less than B)
                                      taken to give the result:          3.11  Floating Point Arithmetic
                           subtract 1  10010 − 1 = 10001
                      1’s complement  −01110                             Certain PLC-related computations are performed using
                                                                         floating point arithmetic. The term floating point refers
                                                                         to the fact that the decimal point can float or be placed
                                                                         anywhere relative to the significant digits of the number.
                     Binary  numbers  are  multiplied  in  the  same  manner   The main features of floating-point representation are:
                   as decimal numbers. When multiplying binary numbers,
                   there are only four conditions that can occur:          •  Floating point can support a much wider range of
                                                                             values. It can represent numbers that are very small
                                        0 × 0 = 0                            or numbers that are very large.
                                        0 × 1 = 0                          •  Floating point provides an easy method of dealing
                                        1 × 0 = 0                            with fractions. Without floating point, a PLC word
                                        1 × 1 = 1                            can only represent an integer or whole number.
                                                                           An example of a floating point number system is shown
                     To multiply numbers with more than one digit, form   in Figure 3-16. The representations shown in this example
                   partial products and add them together, as shown in the
                   following example.
                                                                                     Floating point representation of  4,234
                   Decimal      Equivalent binary                                          423,400.0  ×  10 –2
                                                                                            42,340.0  ×  10 –1
                       5                101                                                 4,234.0  ×  10
                     ×6              ×110                                                     423.4  ×  10 1
                      30                000                                                   42.34  ×  10 2
                                      101                                                     4.234  ×  10 3
                                     101                                                     0.4234  ×  10 4
                                     11110                               Figure 3-16  Example of a floating point number system.



                                                                                 Number Systems and Codes  Chapter 3     57







          pet73842_ch03_046-060.indd   57                                                                               03/11/15   3:50 PM
   71   72   73   74   75   76   77   78   79   80   81