Page 326 - Embedded Microprocessor Systems Real World Design
P. 326

Binary:    0001    1101     1110    0110
                   Hex        1       D        E        6


                 Hex to Decimal
                 Factor each hex digit by  the corresponding power of  16 and sum the results:
                                Hex: 1DE6=(1~16')+(Dx16~)+(Ex16')+(1~16")
                                         =(1~4096)+(13~256)+(14x16)+(6 x1)
                                         =4096+3328+224+6
                                         = 7654,,,

                 Decimal to Hex

                 Divide the number by  16 and write down the remainder. Divide the integer portion of  the
                 previous result by  16 and write down the remainder. Continue this process until the division
                 results in zero. Write the remainders in reverse order for the hex equivalent of the decimal
                 number.
                                      7654/16 = 478 with a remainder of 6
                                   478/16 = 29 with a remainder of 14 (1410 =E,,,)
                                   29/16 = 1 with a remainder of 13   = Dlh)
                                         1/16 = 0 with a remainder of 1

                 Write the remainders, in hex, in reverse order: 1DE6

                                    Math with Binary and Hex Numbers

                 Binary numbers  (and their  hex  representations)  can  be  added  and subtracted just  like
                 decimal numbers. Where most people get into difficulty is in the carry process. When you
                 add two decimal digits, say 9 and 7, you get 16. However, the process of doing this addition
                 involves a carry:
                          9 + 7 = 6 with a carry of  1. The 1 carries into the next, or tens, digit.

                 Similarly, binary numbers have carry properties:
                                              0 + 0 = 0, no carry
                                              0 + 1 = 1, no carry
                                  1 + 1 = 0, with a carry to the next binary position
                 So, if we  add 9 and 7 in binary, it looks like this:
                                                  9 = 10Ol2
                                                 +7 = 011l2
                 We  start by adding the least significant digits:
                                     1 + 1 = 0, with a carry into the next digit


                 Appendix B                                                           307
   321   322   323   324   325   326   327   328   329   330   331