简体   繁体   中英

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 ?

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. What if I know both Java and C# processes are running on Intel X64 architecture? With Java on Linux, C# on Windows. Any details would be interesting.

It should be possible, C# does use IEEE 754 doubles. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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