Page 382 - Programming Microcontrollers in C
P. 382
Coding the Alpha Data 367
restriction did cause a few longer jumps corresponding to 1. Overall,
the table was quite easy to construct.
static const char node[]={
0x1d,0x21,’E’|0x80,0x41,0x21,’O’|0x80,’R’|0x80,0x21,
‘A’|0x80,0x1e,0x21,’H’|0x80,’T’|0x80,0x14,0x21,’\n’|0x80,
‘‘|0x80,0x14,0x21,’N’|0x80,’I’|0x80,0x1f,’L’|0x80,0x12,
‘C’|0x80,0x21,’B’|0x80,0x14,0x12,’G’|0x80,’J’|0x80,0x12,
‘Y’|0x80,0x12,’F’|0x80,’W’|0x80,0x14,0x12,’M’|0x80,
‘S’|0x80,0x12,’D’|0x80,0x15,0x15,0x12,’U’|0x80,’P’|0x80,
‘K’|0x80,0x12,’V’|0x80,0x12,’Z’|0x80,0x12,’X’|0x80,
‘Q’ |0x80
};
int decode(unsigned M[],char *s)
{
unsigned mask,maskdo = ~(~0u>>1);
char i=0,k=0,l=0; /* l is the node pointer,
i is the byte pointer,
M is the message pointer */
mask=maskdo;
while(k !=’\n’)
{
if((mask & M[i])==0)
l+=node[l]>>4;
else
l+=node[l]&0xf;
if(node[l]&0x80)
{ /* if a printable, send it out */
*s++=(k=node[l]&0x7f);
l=0; /* also go to the root node */
}
if((mask>>=1)==0) /* if the mask is 0, turn
on MSB */
{
mask = maskdo;
i++; /* and get the next byte from message */
}
}