The answer to your question: impossible with standard java tools.
Explanation: from this code
Integer.parseInt(cmd_str[i], 16)
We understand that cmd_str[] is array of Strings, because
static int parseInt(String s)
static int parseInt(String s, int radix)
is a method to parse String(not byte, or byte array) into signed Integer.
and what happens in this code
(byte) Integer.parseInt...
Is that this 32 bits of signed integer are being cast to 8bits signed integer. which means if you try to
String bits8string = new String(sent_byte, "AnyStandardCharset");
you will get garbage(or nothing), because chars are not signed integers. Therefore conversion from int to char is not some charset(like ascii) table, because it makes no sense to map characters to negative values.(I have never seen any such table.
here code assembled from yours as a proof:
import java.io.UnsupportedEncodingException;
public class stringbyte16{
public static void main(String cmd_str[]) throws UnsupportedEncodingException{
byte[] sent_byte = new byte[cmd_str.length];
String bits8string="";
for (int i = 0; i < sent_byte.length; i++) {
sent_byte[i] = (byte) Integer.parseInt(cmd_str[i], 16);
System.out.println(sent_byte[i]);
}
bits8string+=new String(sent_byte, "UTF-16");//or "US-ASCII", nothing, etc
System.out.println(bits8string);
}
}
Just run it with hex numbers separated by space(as intended in question)
The only way to fix this is smth like this:
import java.io.UnsupportedEncodingException;
public class stringbyte16{
public static void main(String cmd_str[]) throws UnsupportedEncodingException{
Character HexChar [] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
byte[] sent_byte = new byte[cmd_str.length];
String bits8string="";
for (int i = 0; i < sent_byte.length; i++) {
sent_byte[i] = (byte) Integer.parseInt(cmd_str[i], 16);
System.out.println(sent_byte[i]);
bits8string+=HexChar[(int)sent_byte[i]];
}
System.out.println(bits8string);
}
}