I need a way to create a byte array from various size "bit" arrays?
Let me try explain in an example...
X is represented by 7bits... I have 10 X's (70bits)
Y is represented by 3bits... I have 3 Y's (9bits)
Z is represented by 5bits... I have 1 Z (5bits)
I need to be able to individually set all X,Y,Z. then I need to represent this as a stream of 84bits meaning I need to combine XYZ into a single 11byte array.
You say the data is as I postulated in Reply #2 which (to my mind) means that you have 14 bytes 10 of which have 1 leading 0, 1 has 3 leading zeros and 3 have 5 leading zeros.
Then you seem to want to compact them into a collection of 11 bytes - presumably the first one has 4 leading zeros and the other 10 are all 1s.
If that is the output you want there is no need to worry about the input. Just create an array of 11 bytes all having a value 255 except the first which has the value 15.
However ... how on earth could you extract the original data - assuming that is what is required.
I have an led driver that is controlled via a serial interface tlc5955. U need to write a 769bit "common" shift register.
***Side gripe... who makes registers not a multiple of 8bits???
Anyhow... this register is split up on a bit level... so sets of bits do different things. I am trying to write the control data. It is made up of 48x7bits dot correction, 3x3bit maximum current, 3x7bit global brightness and 1x5bit function control.
I need to write this out the spi line as bytes. For example the 48x7bit dot correction is an array of byte[48] in the code.this allows me to set each one. But to write this out I need only the 7bits from each byte to be joined into a array of 42bytes.
I need to write this out the spi line as bytes. For example the 48x7bit dot correction is an array of byte[48] in the code.this allows me to set each one. But to write this out I need only the 7bits from each byte to be joined into a array of 42bytes.
Ahh - I think the fog is clearing ...
When I suggested in Reply #2 that (for example) X is represented by 01111111 I meant that literally and you did not correct me to explain that the 7 bits can vary depending on the value involved. I had thought that you were using that bit pattern to represent the character 'X' rather than using the standard ascii code.
I can see what needs to be done now, but I don't have a quick answer.
For example the first byte just needs to be shifted 1 bit to the left to lose the leading zero and leave the low bit "empty"
Then the next byte also needs to be shifted 1 but to the left but then its high bit must be placed into the low bit position of the first byte and the remainder of the second byte must be shifted a further place left so as to leave the 2 low bits "empty".
The process for the 3rd byte is similar except that the 2 high bits must go as the low bits in the second byte
and repeat ad nauseum ...
Hint: Looking at the spec for this device (TLC5955) leads me to the conclusion that it is easier to let the compiler do the work of packing the data structure.