M
mathieu
Hi there,
I am looking for comments on the following piece of code: is this
efficiently written ? I am only focusing on little endian system for
now.
out : will contains a buffer of 16bits values where each value is at
most 12bits
in: contains *packed* 12bits value
n: is the size in char of in (multiple of 2).
char *unpack12into16(char *out, const char *in, size_t n)
{
uint16_t *out16 = (uint16_t*)out;
char *pout = out;
const uint8_t *p = (const uint8_t*)in;
const uint8_t * end = p + n;
for(; p != end; )
{
uint8_t b0, b1, b2;
b0 = *p++;
b1 = *p++;
b2 = *p++;
*out16++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f);
*out16++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4);
}
return pout;
}
Thanks
-Mathieu
I am looking for comments on the following piece of code: is this
efficiently written ? I am only focusing on little endian system for
now.
out : will contains a buffer of 16bits values where each value is at
most 12bits
in: contains *packed* 12bits value
n: is the size in char of in (multiple of 2).
char *unpack12into16(char *out, const char *in, size_t n)
{
uint16_t *out16 = (uint16_t*)out;
char *pout = out;
const uint8_t *p = (const uint8_t*)in;
const uint8_t * end = p + n;
for(; p != end; )
{
uint8_t b0, b1, b2;
b0 = *p++;
b1 = *p++;
b2 = *p++;
*out16++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f);
*out16++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4);
}
return pout;
}
Thanks
-Mathieu