How to get the IEEE 754 binary representation of a float in C#

后端 未结 2 1222
小鲜肉
小鲜肉 2020-12-09 09:15

I have some single and double precision floats that I want to write to and read from a byte[]. Is there anything in .Net I can use to convert them to and from their 32 and 6

2条回答
  •  执念已碎
    2020-12-09 09:56

    .NET Single and Double are already in IEEE-754 format. You can use BitConverter.ToSingle() and ToDouble() to convert byte[] to floating point, GetBytes() to go the other way around.

提交回复
热议问题