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

当从C进程发送一个32位整数到Java,C使用小端字节序(LSB先发),而Java默认使用大端字节序(网络字节序)。因此,在Java端接收到数据时,需要进行字节序转换。解决方案是使用Java的网络字节序函数,如`ByteBuffer`或`DataInputStream`来读取数据,确保与C端一致。
摘要由CSDN通过智能技术生成

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.

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?

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?

解决方案

Use the network byte order (big endian), which is the same as Java uses anyway. See man htons for the different translators in C.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值