Here you can find the source of toHex(String str)
public static String toHex(String str)
//package com.java2s; //License from project: Open Source License import javax.xml.bind.DatatypeConverter; public class Main { public static String toHex(String str) { return toHex(str.getBytes()); }//from ww w . j a va 2s . c om public static String toHex(byte[] b) { return DatatypeConverter.printHexBinary(reverse(b)); } public static byte[] reverse(byte[] b) { byte[] b2 = new byte[b.length]; for (int i = 0; i < b.length; i++) b2[b.length - i - 1] = b[i]; return b2; } }