I need help to create the header as explain below, I am not confident with byte conversion and big endian convention.
I think my problem comes from the lines byte[] VERSION = "01".getBytes();
I don't know how to 'force' the String to be stored in one byte.
Header creation
public static final int HEADER_SIZE = 8;
byte[] header = new byte[HEADER_SIZE];
// Header struture
/*
*byte 0 : Version
*byte 1 : Inverse Version
*byte 2-3 : Type
*byte 4-7 : Length
*/
// Hex values
byte[] VERSION = "01".getBytes();
byte[] INVERSE_VERSION = "FE".getBytes();
byte[] TYPE = "9000".getBytes();
byte[] LENGTH = "02".getBytes();
ByteBuffer buf = ByteBuffer.wrap(this.header);
buf.order(ByteOrder.BIG_ENDIAN);
buf.put(VERSION);
buf.put(INVERS_VERSION);
buf.put(TYPE);
//buf.put(LENGTH); <-- Overflow
//out
System.out.println(new String(buf.array(), "ASCII"));
Actual Output
01FE9000
Output Expected
01FE900020000000