I am replacing some C++ code that writes a binary file with C# (net6.0), and I'm noticing an discrepancy between the values written to the file.
If I have a double precision value equal to 0.0, C++ writes the bytes as:
00 00 00 00 00 00 00 00
However C# (using BinaryWriter) is writing the same value as:
00 00 00 00 00 00 00 80
If I convert 0.0 to bytes using System.BitConverter.GetBytes(), I get all 0x00's. If I convert the bytes with 0x80 to a double using BitConverter, it still gives me 0.0.
byte[] zero = System.BitConverter.GetBytes(0.0); // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
bool equal = 0.0 == System.BitConverter.ToDouble(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}); // true
This doesn't seem like it will cause any problems, but I'd like to understand what's going on.