M
ma740988
I'm trying to unpack a 32 bit word into 3-10 bits samples. So now:
Sample0 corresponds to bits 0-9
Sample1 corresponds to bits 10-19
Sample2 corresponds to bits 20-29
Bits 30 and 31 are don't cares
So my unpacker looks like:
void unpack(
unsigned int *beg,
unsigned int *end,
float* dest)
{
const unsigned int mask=(1<<20)-1;
while (beg!=end)
{
*dest++ = *beg & mask;
*dest++ = *beg >> 20 & ((1<<10)-1);
++beg;
}
}
Usage:
unsigned int val(0xA5A5A5);
float dest[3];
unpack (&val, &val+1, dest);
I'd like a - sort of - generic approach that'll acount for floats and
doubles. I suspect I should also use a vector, nonetheless critiques
and/or a more refined implementation welcome.
Sample0 corresponds to bits 0-9
Sample1 corresponds to bits 10-19
Sample2 corresponds to bits 20-29
Bits 30 and 31 are don't cares
So my unpacker looks like:
void unpack(
unsigned int *beg,
unsigned int *end,
float* dest)
{
const unsigned int mask=(1<<20)-1;
while (beg!=end)
{
*dest++ = *beg & mask;
*dest++ = *beg >> 20 & ((1<<10)-1);
++beg;
}
}
Usage:
unsigned int val(0xA5A5A5);
float dest[3];
unpack (&val, &val+1, dest);
I'd like a - sort of - generic approach that'll acount for floats and
doubles. I suspect I should also use a vector, nonetheless critiques
and/or a more refined implementation welcome.