I'm developing app that will send data over RTP
, but I almost never worked with bytes. Right now I'm trying to use BitArray
:
byte[] toSend = new byte[12];
BitArray b = new BitArray(new int[] { 2 });
b.CopyTo(toSend, 0);
but it works with Int32
, so 2 is represented like 0100..0
, and that's not what I need. I have 2 questions here:
How should i combine
2|1|1|4
bits into one byte? I think there should be something that looks like:int version = 2;//2 bits int padding = 0;//1 bit int extension = 0;//1 bit int ccrc = 0;//4 bits byte[] toSend = new byte[1]{version+padding+extension+ccrc};
For some headers there are 16 bits reserved, so i need something like this:
0000000000000000(16)
, but i don't know how to create this kind of variable, and how to write 16 bits into two bytes.