Android | LSB& MSB

时间:2017-05-29 08:38:15

标签: android arrays byte endianness

在向设备发送请求期间,我遇到了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

问题是 - 我需要将byteData [36]设置为LSB,将byteData [39]设置为MSB。你能帮帮我吗?在此先感谢:)

1 个答案:

答案 0 :(得分:1)

sklearn.svm referencethis回复ByteOrder.BIG_ENDIANByteOrder.LITTLE_ENDIAN订单更改:

ByteBuffer b = ByteBuffer.allocate(4);
b.order(ByteOrder.LITTLE_ENDIAN);
b.putInt(14);
byte[] result = b.array();

在这种情况下b[0] == 14

相关问题