0

I've got problem with LSB and MSB during sending request to the device. I need to send sessionId(int). It needs to be send on four bytes. Right now I'm sending byte array like this :
So , for example if sessionID is 14 I'm sending :

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

The problem is - I need to set byteData[36] as LSB and byteData[39] as MSB. Could you help me with this ? Thanks in advance :)

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Bartos
  • 1,007
  • 3
  • 15
  • 38

1 Answers1

1

From this answer of Gregory Pakosz with ByteOrder.BIG_ENDIAN to ByteOrder.LITTLE_ENDIAN order change:

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

In this case b[0] == 14.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79