我问,因为我正在从C进程向Java发送字节流。在C端,32位整数的LSB是第一个字节,MSB是第4个字节。
I ask because I am sending a byte stream from a C process to Java. On the C side the 32 bit integer has the LSB is the first byte and MSB is the 4th byte.
所以我的问题是:在Java方面,当我们阅读从C进程发送的字节是什么,Java端的 endian 是什么?
So my question is: On the Java side when we read the byte as it was sent from the C process, what is endian on the Java side?
后续问题:如果Java端的endian与发送的端序不同,我该如何在它们之间进行转换?
A follow-up question: If the endian on the Java side is not the same as the one sent, how can I convert between them?
推荐答案使用网络字节顺序(big endian),它与Java使用的相同。请参阅C中的不同翻译人员。
Use the network byte order (big endian), which is the same as Java uses anyway. See man htons for the different translators in C.
更多推荐
Java是以小端还是大端读取整数?
发布评论