I'd like to convert a given float
into its binary representation. I tried to write the float value into a MemoryStream
, read this MemoryStream
byte by byte and convert the bytes into their binary representation. But every attempt failed.
MemoryStream
was 0, when I didn't flush the StreamWriter
, and 1, when I did.I'm sure there is a better way to convert float
s to binary, but I also wanted to learn a little bit about the MemoryStream
class.
You can use BitConverter.GetBytes(float)
or use a BinaryWriter
wrapping a MemoryStream
and use BinaryWriter.Write(float)
. It's not clear exactly what you did with a MemoryStream
before, but you don't want to use StreamWriter
- that's for text.