Convert a byte array to a Hex string in Java
Description
The following code shows how to convert a byte array to a Hex string.
Example
// www . j av a 2s .c o m
public class Main {
public static void main(String[] argv) {
byte[] b = "ada".getBytes();
for (int i = 0; i < b.length; i++) {
System.out.println(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »