21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

#define MAX_WORDLEN 4<br />

/* len parameter is measured in bytes. Remaining bits padded with 0. */<br />

unsigned char *spc_bin2words(const unsigned char *str, size_t len) {<br />

short add_space = 0;<br />

size_t i, leftbits, leftovers, scratch = 0, scratch_bits = 0;<br />

unsigned char *p, *res;<br />

res = (unsigned char *)malloc((len * 8 / BITS_IN_LIST + 1) * (MAX_WORDLEN + 1));<br />

if (!res) abort( );<br />

res[0] = 0;<br />

for (i = 0; i < len; i++) {<br />

leftovers = str[i];<br />

leftbits = 8;<br />

while (leftbits) {<br />

if (scratch_bits + leftbits (leftbits - (BITS_IN_LIST - scratch_bits)));<br />

leftbits -= (BITS_IN_LIST - scratch_bits);<br />

leftovers &= ((1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!