I assume the title of this thread is an error?
I assume that you have noticed that 810 8 bit words (or bytes) contain exactly the same number of data bits as 720 bit words, i.e. you data must not have any padding bits.
Anyway bit fields will not help, if you consider this structure
- typedef struct word_9bit
-
{
-
unsigned int bit_0:1;
-
unsigned int bit_1:1;
-
unsigned int bit_2:1;
-
unsigned int bit_3:1;
-
unsigned int bit_4:1;
-
unsigned int bit_5:1;
-
unsigned int bit_6:1;
-
unsigned int bit_7:1;
-
unsigned int bit_8:1;
-
} WORD_9BIT
This would hold a 9 bit word, however if you were to take the size of this structure you would find it was 2 bytes, there are 7 padding bits at the end of the structure. Most c compilers would place in memory 2 byte aligned, i.e. at a even byte boundary.
What this means is that it you had an array of these
WORD_9BIT array[2];
That there will be 7 padding bits between the data for the 2 structures, as stated above you don't want padding bits.
If you put a 9 bit word in an array of bytes (8 bit words) then you will always be crossing 1 and only 1 byte boundary (this is not true for higher bit values, for instance a 10 bit word could cross 1 or 2 byte boundaries).
So to put the 9 bit word into the byte array you will have to do a shift, mask and or operation for the high and low bytes, for a given 9 bit word in an array of 9 bit words it would be relatively easy to calculate these byte offsets and shif and mask values.
In light of this I think my approach would be to create a 9 bit word array class and then overload the array operator [] to allow you to treat your array of 9 bit words exactly like a normal array of words but resulting in an array of bytes containing the actual data.