I need to write a 8 bit packet, that includes 3 ints, in this division:
int1 = 1 bit
int2 = 1 bit
int3 = 6 bit
I don't know how to do that. I can write some 4 bytes packets, using this function which work for us:
buffer.AddRange(BitConverter.GetBytes(_value));
But I need help in writing a 8 bit packet divided in many ints (or bit elements). I have read about BitArray, but I really don't know how to use it. I have written some code, but don't know if it really is going to work:
bool playback = false;
bool extExerciseNum = false;
BitArray byte4 = new BitArray(2);
byte4.Set(0, playback);
byte4.Set(1, extExerciseNum);
Here I pretend to create a BitArray with the first 2 individual ints.
int exerciseNumber = 23;
BitArray b = new BitArray(new int[] { exerciseNumber });
int[] bits = b.Cast<bool>().Select(bit => bit ? 1 : 0).ToArray();
And here, I pretend to write a 6 bit length BitArray (I don't understand it properly, by the way).
Anyone can help me how to write this package properly? Thank you so much!!