$ cat 879430.cpp #include int *decode(unsigned char *buf, int buflen) { static int retval[201]; int tmp=0; int mask=0; int *outbuf=retval; unsigned char *end=buf+buflen; while (buf < end) { int t=*buf & 0xc0; if (t==0xc0) { tmp =*buf++<<16; tmp|=*buf++<<8; tmp|=*buf++; mask=0x3fffff; } else if (t==0x80) { tmp =*buf++<<8; tmp|=*buf++; mask=0x3fff; } else { tmp =*buf++; mask=0x7f; } *outbuf++ = tmp&mask; } *outbuf++ = -1; // sentinel value: EOList return retval; } unsigned char foo[] = { 0x55, // 85 0xaa, 0xaa, // 10922 0xcc, 0xcc, 0xcc, // 838860 0 }; int main( void ) { int *t = decode(foo, sizeof(foo)); while (*t != -1) { printf("0x%06x %7u\n", *t, *t); t++; } return 1; } $ gcc 879430.cpp -lstdc++ $ ./a.out 0x000055 85 0x002aaa 10922 0x0ccccc 838860 0x000000 0