Page 258 - Programming Microcontrollers in C
P. 258
Data Compression 243
character that was output from the program is a ‘\n’. Recall the way
that the tree was built. If an incoming bit is 0, the next node in the
tree will be taken. If the incoming bit is 1, the content of the current
node will be added to the node pointer to determine the next node in
the tree. If at any time a negative number is found in the tree, a leaf
has been found. The data portion of this byte, bits 0 through 6, will
be sent out to the screen.
After each bit is processed, the next bit in the sequence must be
processed. The next bit is selected by shifting the mask byte to the
right one bit. If the result of this shift creates a zero mask, a new
mask with a value of 0x80 is created and the next byte from the
incoming message code is selected when i is incremented.
The simple program below causes the nine messages to be printed
on the screen:
main()
{
decode(M1);
decode(M2);
decode(M3);
decode(M4);
decode(M5);
decode(M6);
decode(M7);
decode(M8);
decode(M9);
}
Listing 5-2: Message Printing Program
The result of execution of this program is shown below. The nine
messages contain 124 characters that would require 992 bits of
memory to store the messages in standard ASCII format. The encoded
sequence requires 500 bits or 63 bytes of storage.
ALTITUDE
HEADING
DISTANCE REMAINING
FUEL REMAINING
AIR SPEED