I am working with a device that supports little endian byte order. How do I do this in Java?
I have created a byte stream from the hex data and wrote it to the socket output stream. I am supposed to send data in the following format.
Protocol-Version: 0x0001
Request_Code: 0x0011
Request_Size: 0x00000008
String s = "0001001100000008";
byte[] bytes = hexStringToByteArray(s);
socket.getOutputStream().write(bytes);
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}
I am however not receiving any response from the device for this request. Am I doing something wrong?