I just read the thread, and someone mentioned C, so here goes:

$ cat 879430.cpp #include <stdio.h> 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

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: [NOT] How would you decode this? by roboticus
in thread [NOT] How would you decode this? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.