I am trying to cast a float into a byte array of length 4, and then back again. But I it doesn's seems to work.
Here's what I've done:
byte[] b = BitConverter.GetBytes(90);
float fb = BitConverter.ToSingle(b, 0);
I expected fb = 90, but it's 1.26E-43.
I know that my converter is little endian, so I've also tried to reverse the array, like this:
byte[] b = BitConverter.GetBytes(90);
Array.Reverse(b);
float fb = BitConverter.ToSingle(b, 0);
Then I got the answer fb = 9.0E+15.
Any ideas? Thanks in advance!
90
is anint
, not afloat
.90f
is afloat
. In either case, whatever you're doing here is quite possibly the wrong thing to do -- occasionally there is a useful need for converting afloat
into bytes usingBitConverter
, but for most serialization purposes it's actually not the right tool. – Overskirt