在向设备发送请求时,我遇到了LSB和MSB的问题。我需要发送sessionId(int)。它需要在四个字节上发送。现在,我像这样发送字节数组:
例如,如果sessionID是14,我发送:
public static final byte[] intToByteArray(int value) {
return new byte[] {
(byte)(value >>> 24),
(byte)(value >>> 16),
(byte)(value >>> 8),
(byte)value};
}
byteData[36] - 0
byteData[37] - 0
byteData[38] - 0
byteData[39] - 14问题是-我需要将byteData36设置为LSB,将byteData39设置为MSB。你能帮我弄一下这个吗?提前感谢:)
发布于 2017-05-29 18:48:29
从带有ByteOrder.BIG_ENDIAN的Gregory Pakosz的this应答到ByteOrder.LITTLE_ENDIAN订单更改:
ByteBuffer b = ByteBuffer.allocate(4);
b.order(ByteOrder.LITTLE_ENDIAN);
b.putInt(14);
byte[] result = b.array();在本例中为b[0] == 14。
https://stackoverflow.com/questions/44238061
复制相似问题