I need to build a stream of bytes, by writing int and float/double data into it. How do I easily accomplish this in C#? I'm aware of the method to get the raw bytes of a float variable, but does C# already have a byte-stream writing system that I could easily leverage?
Reading a float value from a bytearray:
uint floatBytes = .. // read 4 float bytes from byte[] array
float floatVal = *((float*)&floatBytes);
Writing a float value into bytearray:
float floatVal = ... // read a float from the float[] array
uint floatBytes = *((uint*)&floatVal);