Tuesday, November 29, 2011

Java: Converting a byte array into Hexadecimal String


Share at Facebook

I have written a method named byteArrayToHexString() which takes a byte array as parameter, and returns the Hexadecimal representation of the byte array. Below is the method.


public static String byteArrayToHexString(byte []input){
String string = "";
if(input == null){
return string;
}

for(byte b : input){
string += Integer.toHexString(Integer.parseInt(Byte.toString(b))).toUpperCase();
}

return string;
}




No comments: