in reply to unpacking 6-bit values
A relatively simple C program to do the task:
roboticus@Boink~ $ cat 876421.cpp #include <stdio.h> unsigned char inbuf[]="Now is the time for all "; unsigned char outbuf[50]; void hexdump(unsigned char *p, int n) { for (int i=0; i<n; i++) { printf("%02x ", *p++); } puts("\n"); } int main(int, char **) { unsigned char *src = inbuf; unsigned char *srcEnd = src + sizeof(inbuf); unsigned char *dst = outbuf; hexdump(src, sizeof(inbuf)); int rem = 0; int st = 0; while (src != srcEnd) { switch (st) { case 0: rem = *src >> 6; *dst++ = *src++ & 0x3f; st = 1; break; case 1: *dst++ = ((*src&0x0f)<<2) | rem; rem = *src++>>4; st = 2; break; case 2: *dst++ = ((*src&0x03)<<4) | rem; *dst++ = *src++>>2; st = 0; break; } } hexdump(outbuf, dst-outbuf); } roboticus@Boink~marco@Boink:~ $ gcc 876421.cpp -lstdc++ roboticus@Boink:~ $ ./a.out 4e 6f 77 20 69 73 20 74 68 65 20 74 69 6d 65 20 66 6f 72 20 61 6c 6c 2 +0 00 0e 3d 36 1d 20 24 36 1c 20 10 07 1a 25 01 02 1d 29 35 16 19 20 18 36 1 +b 32 01 12 18 2c 31 06 08 00
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|