Page 378 - Programming Microcontrollers in C
P. 378

Coding the Alpha Data     363

                              h             000001
                              i             1100
                              j             000011001
                              k             1111111
                              l             1110
                              m             111100
                              n             1101
                              o             0011
                              p             111111001
                              q             11111101111
                              r             0010
                              s             111101
                              t             000000
                              u             111111000
                              v             111111010
                              w             0000110111
                              x             11111101110
                              y             000011010
                              z             1111110110

                              Table 7-1: Huffman Code for Compressing Telephone Book Names

                              The encoding routine is shown in Listing 7-6. Contained in the
                          listing of the encoding routine is a look-up table that contains all of the
                          codes. In this table, the first two entries correspond to a space character
                          and a new line character. The following entries correspond to the letters
                          in the alphabet. In other words, the third entry corresponds to the letter
                          A and the seventh entry corresponds to the letter E. Notice that this
                          table is defined as external, but it is labeled static so that there is no
                          linkage to the table outside of the file encode.c.
                              In operation, this function receives three parameters. The first is
                          a pointer to an array that contains the data to be encoded. This array
                          contains a zero terminated string. The second array of unsigned
                          integers is named array. Its length is the third passed parameter
                          length. Encoded data are all loaded into this array. All of the local
                          variables used by  encode are straightforward. The variable
                          bitbase is an unsigned int with its most significant bit set to
                          one and the remainder of its bits zero. When the function is executed,
                          the array[] is first filled with zeros. The variable i is initialized
   373   374   375   376   377   378   379   380   381   382   383