简体   繁体   English

Java Double.doubleToLongBits进入C#BitConverter.ToDouble

[英]Java Double.doubleToLongBits into C# BitConverter.ToDouble

Can I convert a Java double to 8 bytes using java.lang.Double.doubleToLongBits , write to network, then read those bits in C# using BitConverter.ToDouble ? 我可以使用java.lang.Double.doubleToLongBits将Java double转换为8个字节,写入网络,然后使用BitConverter.ToDouble读取C#中的那些位吗?

Given the C# docs make no mention of IEEE 754 but do talk about endianness, indicating platform dependence, I suspect not in the general case. 鉴于C#文档没有提到IEEE 754,而是谈论字节顺序,表示平台依赖性,我怀疑一般情况下不会。 What if I know both Java and C# processes are running on Intel X64 architecture? 如果我知道Java和C#进程都在Intel X64体系结构上运行怎么办? With Java on Linux, C# on Windows. 在Linux上使用Java,在Windows上使用C#。 Any details would be interesting. 任何细节都会很有趣。

It should be possible, C# does use IEEE 754 doubles. C#应该有可能使用IEEE 754 double。 The only problem might be the endianness when transfering them over the network, so just choose the one your architecture is using and it should transfer correctly. 唯一的问题可能是通过网络传输它们时的字节序,因此只需选择您的体系结构正在使用的帧,它就可以正确传输。

Note, if you use a ByteBuffer , you can select the desired endian easily. 注意,如果使用ByteBuffer ,则可以轻松选择所需的字节序。 Just use its double functions, no need to use doubleToLongBits -- that's just there in case you need the double representation to be converted to a long. 只需使用其double函数,无需使用doubleToLongBits -仅在需要将double表示形式转换为long的情况下可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM