I have a byte array that consists of a 10 byte message. I know the first 2 bytes contains an id that would like to extract out to a string. An example of this id is: 2001. The remaining bytes consist of other fields which I am aware.
I am receiving the binary data from a UDP message and after attempting to convert the binary/ byte array with the methods below, my print still logs a binary message.
The code I am using is as follows to convert the binary UDP message:
DatagramPacket rcvMsg = receivepacket.getData();
String id = new String(rcvMsg, 0, 2, "US-ASCII");
System.out.println("id ----- : "+id);
How can I get this to print 2001 from the binary datagram message?