Reputation: 7030
I have a byte array. I need to show its bytes on screen. How can I turn the bytes into a string representation without any conversion?
*By conversion, in this context I mean not decoding it into ASCII or any other equivalent encoding system
So for instance, if I have:
byte[] a = { 0x3F, 0x2C, 0x6A };
I'd like results like this:
String[] b = { "3F", "2C", 6A"};
Upvotes: 0
Views: 235
Reputation: 616
Give this a try
Byte[] a = {31,22,62};
System.out.println(Arrays.deepToString(a));
Upvotes: 0
Reputation: 156384
byte[] a = { 0x3F, 0x2C, 0x6A };
String[] s = new String[a.length];
for (int i=0; i<a.length; i++) {
s[i] = String.format("%02X", a[i]);
}
// s => ["3F", "2C", "6A"]
Upvotes: 6