Page 34 - ARM 64 Bit Assembly Language
P. 34

Introduction  17

                     Example 6. Conversion from binary to decimal.

                                1. If the most significant bit is ‘1’, then
                                    a. Find the two’s complement
                                    b. Convert the result to base 10
                                    c. Add a negative sign
                                2. else
                                    a. Convert the result to base 10


                                 Number        one’s Complement  two’s Complement  Base 10  Negative
                                11010010          00101101         00101110        46       −46
                             1111111100010110  0000000011101001  0000000011101010  234     −234
                                01110100         Not negative                      116
                             1000001101010110  0111110010101001  0111110010101010  31914  −31914
                             0101001111011011    Not negative                     21467


                     Example 7. Conversion from decimal to binary.

                                    1. Remove the negative sign
                                    2. Convert the number to binary
                                    3. Take the two’s complement


                                 Base 10    Positive Binary  one’s Complement  two’s Complement
                                   −46        00101110          11010001         11010010
                                  −234    0000000011101010  1111111100010101  1111111100010110
                                  −116        01110100          10001011         10001100
                                 −31914   0111110010101010  1000001101010110  1000001101010111
                                 −21467   0101001111011011  1010110000100100  1010110000100101

                     Subtraction using complements

                     One very useful feature of complement notation is that it can be used to perform subtraction
                     by using addition. Given two numbers in base b, x b and y b , the difference can be computed
                     as:


                                                  z b = x b − y b                                   (1.2)
                                                                n
                                                      = x b + (b − y b ) − b n                      (1.3)
                                                                       n
                                                      = x b + C(y b ) − b ,                         (1.4)

                     where C(y b ) is the radix complement of y b . Assume that x b and y b , both positive and y b ≤ x b
                     and both numbers have the same number of digits n (y b may have leading zeros). In this case,
   29   30   31   32   33   34   35   36   37   38   39