Please check this code
float f = BitConverter.ToSingle(new byte[] { 0xBF, 0x04, 0x8E, 0xFF }, 0);
byte[] b = BitConverter.GetBytes(f);
this yeilds a strange result. b will be { 0xBF, 0x04, 0xCE, 0xFF }
I guess it is because the value of f is NaN. the reason I'm asking this question is because I use Marsal to convert a stream of bytes into a struct that contains a float, the I swap endianity
The thing is when I get to the field is already messed up (like the above example)
any ideas?
Thanks!
BitConverterin both directions, endianness isn't a concern - indeed, that would be the issue if the bytes were reversed, not if they are just mutated{ 0xBF, 0x04, 0x8E, 0xFF }) is the wrong way around. That makes a NaN, and then things start going south.