I am writing some signal processing code in C that has a communications channel. At the output I get a bunch of bits as they arrive.
for (n=0; n<BUFFER_LENGTH; n++) {
/* do some processing that calculates x */
output[n] = x > 0;
}
Here are my questions:
- Is there a good type to represent
the output array? At first I thought
uint1_t would be ideal but I hear
that doesn’t necessarily represent
one bit in memory. - Once I find a
sync pattern in the data I know the
format of the next bits, how can I
convert a bunch of 1’s and 0’s in
the array into integers, floats,
doubles, characters, etc.? I’ve heard of using
a union but I don’t think that will work with an
array of bits.
Just store the data in a sufficiently large block of bytes and then iterate through the bits using shifting and masking to extract individual bits sequentially.
e.g. to print out the contents of a buffer as individual bits: