java中bitconverter_Java Double.doubleToLongBits到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. 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.

鑒於C#docs沒有提及IEEE 754,但確實談到了字節順序,表明平台依賴性,我懷疑不是一般情況。如果我知道Java和C#進程都在Intel X64架構上運行怎么辦?在Linux上使用Java,在Windows上使用C#。任何細節都會很有趣。

1 个解决方案

#1

2

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.

應該可以,C#確實使用IEEE 754雙打。唯一的問題可能是通過網絡傳輸時的字節序,所以只需選擇您的架構正在使用的那個,它應該正確傳輸。

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.

注意,如果使用ByteBuffer,則可以輕松選擇所需的字節序。只需使用它的雙重函數,不需要使用doubleToLongBits - 這就是你需要將雙重表示轉換為long的情況。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值