Does Java read integers in little endian or big endian?

后端 未结 8 1709
孤城傲影
孤城傲影 2020-11-27 13:30

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 ques

相关标签:
8条回答
  • 2020-11-27 13:57

    I would read the bytes one by one, and combine them into a long value. That way you control the endianness, and the communication process is transparent.

    0 讨论(0)
  • 2020-11-27 14:01

    There's no way this could influence anything in Java, since there's no (direct non-API) way to map some bytes directly into an int in Java.

    Every API that does this or something similar defines the behaviour pretty precisely, so you should look up the documentation of that API.

    0 讨论(0)
提交回复
热议问题