#include <stdio.h>
// 0AAAA0BB BB0CCCC0 DDDD0EEE E0FFFF0G GGG0HHHH
void convert(unsigned char five[], unsigned char four[]) {
four[0] = (five[0] << 1) & 0xF0 // 11110000
| (five[0] << 2) & 0x0C // 00001100
| (five[1] >> 6) & 0x03; // 00000011
four[1] = (five[1] << 3) & 0xF0 // 11110000
| (five[2] >> 4) & 0x0F; // 00001111
four[2] = (five[2] << 5) & 0xE0 // 11100000
| (five[3] >> 3) & 0x10 // 00010000
| (five[3] >> 2) & 0x0F; // 00001111
four[3] = (five[3] << 7) & 0x80 // 10000000
| (five[4] >> 1) & 0x70 // 01110000
| (five[4]) & 0x0F; // 00001111
}
void show(unsigned char string[], int length) {
int i;
for (i = 0; i < length; i ++)
printf (" %02X", (int)string[i]);
}
void convertAndShow(unsigned char five[], unsigned char four[]) {
show (five, 5);
convert (five, four);
printf ("%5s", "");
show(four, 4);
puts ("");
}
int main() {
unsigned char result[4];
convertAndShow ((unsigned char []){ 0x08, 0x42, 0x10, 0x84, 0x21 }, result);
convertAndShow ((unsigned char []){ 0x10, 0x84, 0x21, 0x8C, 0x63 }, result);
convertAndShow ((unsigned char []){ 0x52, 0xD8, 0xD0, 0x88, 0x64 }, result);
convertAndShow ((unsigned char []){ 0x21, 0x4E, 0x84, 0x98, 0x62 }, result);
convertAndShow ((unsigned char []){ 0x7B, 0xDE, 0xF7, 0xBD, 0xEF }, result);
return 0;
}