I am reading over some code and I finally need to figure out how this function works. I understand what it is used for and why it is used, but further than that, its magic.
From what I understand the function takes in a value that had all the info compressed into it. So instead of having 16 integers that only hold the value 0 or 1, it packs each 0 or 1 value into the bits of the integer. And this function takes those bits out and puts them each into a char.
The function is called like so
DecompressInputs(DigOut[0], &input[64]);
With DigOut and input being an arrays defined as such
UWORD DigOut[2];
char input[NUM_INPUTS]; // NUM_INPUTS = 80
And the function itself
/*===============================================*/
/* Name: DecompressInputs */
/* Purpose: Convert a 16 bit value into an array */
/* of 16 boolean values. */
/*===============================================*/
static __inline__ void DecompressInputs(int bits,char *input)
{
char i = 16;
while(i)
{
if(bits & 0x0001)
*input++ = 0x0a5;
else
*input++ = 0x000;
bits = bits >> 1;
i-=1;
}
}