Java是以小端还是大端读取整数?

编程入门 行业动态 更新时间:2024-10-28 19:28:04
本文介绍了Java是以小端还是大端读取整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我问,因为我正在从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是以小端还是大端读取整数?

本文发布于:2023-07-29 19:41:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1243487.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大端   整数   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!