How to get the IEEE 754 binary representation of a float in C#
问题 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 64 bit IEEE 754 representations? 回答1: .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. 回答2: Update for current .NET/C# using spans: static void Main() { Span<byte> data = stackalloc byte[20];