I had a problem trying to move groups of 17-bit data into a byte array. I do not want to go step by step, but I cannot understand the logical loop.
I need this because I have to calculate the checksum by adding all byte values after combining them like this. So that’s what I’m afraid of.
I have 16 byte arrays. The first 3 bytes of the array contain 17 bits that I received after. (8 bits from [0], 8 bits from [1]and MSB from [2].)
I need to transfer these 16 17-bit values into one separate byte array.
The first is easy:
int index = 0;
myArray[index++] = driverData[driver][0]; //First byte
myArray[index++] = driverData[driver][1]; //Second byte
myArray[index] = (driverData[driver][2] & 0x80) << 7; //First bit of the third byte.
Hence, however, it is more difficult to try to execute any cycle in order to move them.
driver++;<br>
//Take the 7 MSBs from the data array.
myArray[index++] |= (byte)(driverData[driver][0] & 0x7e >> 1);
//This leaves a single bit left over on driverData[driver][0].
myArray[index] = (byte)(driverData[driver][1] & 0x1 << 7);
, . ? - ?