2

I have a byte array that I want to convert its value in hexadecimal.

byte array = [48, 48, 28, ...]

--->

hex byte array = [30, 30, 1C, ...]

3
  • Here is a solution: stackoverflow.com/questions/9655181/… Just don't return a String of the array, but rather the converted array itself Commented Apr 15, 2013 at 10:12
  • There is no such thing as a 'hex byte array'. Hex is how you view it, print it, report it. Not a real question. Commented Apr 15, 2013 at 10:15
  • why is this tagged with android? Commented Apr 15, 2013 at 10:21

2 Answers 2

3

This should work. Maybe you have to convert byte to int if its not casted implicitly.

String[] hexArray = new String[byteArray.length];
for(int index = 0; index < byteArray.length; index++) {
    hexArray[index] = Integer.toHexString(byteArray[index]);
    // maybe you have to convert your byte to int before this can be done
    // (cannot check reight now)
}
Sign up to request clarification or add additional context in comments.

1 Comment

hexadecial is only the representation. an array of byte will always have value from 0 to 255 and not display as 00 to FF unless you convert it to a String representation like with the Integer.toHexString() method
1

check Integer.toHexString method. iT will convert an int to a hex string. so iterate through your array and convert each number.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.