int[] png = { -119, 80, 78, 71, 13, 10, 26, 10 };
should be equal to an array of string as follows.
89 50 4E 47 0D 0A 1A 0A
I have tried with Integer.toHexString(-119) but it end up converting into ffffff89 but it should be equal to 89.
int[] png = { -119, 80, 78, 71, 13, 10, 26, 10 };
should be equal to an array of string as follows.
89 50 4E 47 0D 0A 1A 0A
I have tried with Integer.toHexString(-119) but it end up converting into ffffff89 but it should be equal to 89.
StringBuffer and format() of String Class can help you here.
For example,
String.format("%02X ", value);
Here is how you can iterate through the array to convert it to Hex.
public class ConvertToHexaDecimal {
static int[] png = { -119, 80, 78, 71, 13, 10, 26, 10 };
public static void main(String[] args){
StringBuilder sb = new StringBuilder();
for (int value : png ) {
sb.append(String.format("%02X ", value));
}
System.out.println(sb.toString());
}
}