Check out this example:
Input:
public class ByteHex {
public static void main(String[] args) {
byte[] bytes = {10, 2, 15, 11};
for; (byte b : bytes) {
String st = String.format("%02X", b);
System.out.print(st);
}
}
}
Output:
0A020F0B
In this program, we have a byte array named bytes. To convert byte array to a hex value, we loop over each byte in the array and use String's format().
%02X is used to print two places (02) of Hexadecimal (X) value and store it in the string st.
I hope this will help you, Happy Learning...!!