Page 27 - ARM 64 Bit Assembly Language
P. 27

10 Chapter 1

                  characters. We use the digits 0 through 9 plus the letters A through F. Table 1.2 shows the
                  equivalents for all numbers between 0 and 20 in base two through base ten, and base sixteen.
                  Before learning assembly language it is essential to know how to convert from any base to
                  any other base. Since we are already comfortable working in base ten, we will use that as an
                  intermediary when converting between two arbitrary bases. For instance, if we want to convert
                  a number in base three to base five, we will do it by first converting the base three number to
                  base ten, then from base ten to base five. By using this two-stage process, we will only need to
                  learn to convert between base ten and any arbitrary base b.


                  1.3.2.1 Base b to decimal

                  Converting from an arbitrary base b to base ten simply involves multiplying each base b digit
                       n
                  d by b ,where n is the significance of digit d, and summing all of the results. For example,
                  converting the base five number 3421 5 to base ten is performed as follows:

                                                      3
                                                                       1
                                                              2
                                      3421 5 = 3 × 5 + 4 × 5 + 2 × 5 + 1 × 5   0
                                              = 375 10 + 100 10 + 10 10 + 1 10
                                              = 486 10
                  This conversion procedure works for converting any integer from any arbitrary base b to its
                  equivalent representation in base ten. Example 1 gives another specific example of how to
                  convert from base b to base ten.
                  Example 1. Converting from an arbitrary base to base ten.


                                       Converting 4362 7 to base ten is accomplished
                                          by expanding and summing the terms:
                                                      3
                                                                      1
                                                              2
                                      4362 7 = 4 × 7 + 3 × 7 + 6 × 7 + 2 × 7   0
                                              = 4 × 343 + 3 × 49 + 6 × 7 + 2 × 1
                                              = 1372 + 147 + 42 + 2
                                              = 1563 10


                  1.3.2.2 Decimal to base b

                  Converting from base ten to an arbitrary base b involves repeated division by the base, b.Af-
                  ter each division, the remainder is used as the next more significant digit in the base b number,
                  and the quotient is used as the dividend for the next iteration. The process is repeated until the
                  quotient is zero. For example, converting 56 10 to base 4 is accomplished as follows:
   22   23   24   25   26   27   28   29   30   31   32