I want to create a memory stream that contains int32, int16, single values. Using binarywriter is useless, so I tried to create an array of bytes. Since the values ββare of different types, I do not know how to do this correctly. So I am trying to do this:
byte[] tab = new byte[]{2,0,0,0,3,0,3,0} - 2 - int32 (four bytes), two more 3 - int16 (two bytes)
works fine, but when I want to add some values, it generates errors. I can not do this:
byte[] tab = new byte[]{2,0,0,0,3,0,3,0,4.4f,5.6f}
I must have the stream in the correct format, because this stream will be read in this method:
short[] rawData;
float[] modulusData;
public void rawData(Stream s)
{
BinaryReader br = new BinaryReader(s);
int dataCount = br.ReadInt32();
if (dataCount > 0)
{
rawData = new short[dataCount];
for (int i = 0; i < dataCount; i++)
rawData[i] = br.ReadInt16();
}
else
rawData = new short[0];
dataCount = br.ReadInt32();
if (dataCount > 0)
{
modulusData = new float[dataCount];
for (int i = 0; i < dataCount; i++)
modulusData[i] = br.ReadSingle();
}
else
modulusData = new float[0];
}
Does anyone have an idea how to do this?