Java是以小端还是大端读取整数? [英] Does Java read integers in little endian or big endian?

查看:2408
本文介绍了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是以小端还是大端读取整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆