I need to form a 20-byte data packet and send the payload to the hardware peripheral via Bluetooth.
This 20-byte data packet is divided into 14 data sets internally, each of 11 bits, the last 6 bits must be a null character.
Therefore, Total: 160 bits (20 bytes) = 14 (sets) * 11 (bits) + 6 (null characters)
11 bits are again divided into 3 sets of 2 bits, 3 bits and 6 bits each. However, this is not important for the main question, at present I can form 11 bits by taking "Int16". I will do a shift operation to filter 11 bits, I know that.
If I have only one data set, then I have to fill in all 20 bytes, except for the first 11 bits with a null character, if there are two data sets, then all but 22 bits should have a null character and, accordingly.
The problem I am facing is to generate these consecutive 160 bits due to the odd bits, which are 11. I thought about doing the "Int" and do shift (<<) operations, and then doing bitwise OR (| ) but Int is 64 bits.
Currently, I think that using an array of characters with a fixed size of 20 will fit this situation. Although conceptually I consider this the best way, programmatically I can’t form a logic with all the conditions to achieve this. I think I need to put all the logic in a loop.
Can anyone say that this is the right way to achieve this, and help me solve it if this is the best way. Or indicate any other method, if available.