Java examples for java.lang:Hex
Convert String to Hex String
import java.math.BigDecimal; import java.security.MessageDigest; import org.apache.log4j.Logger; public class Main{ public static void main(String[] argv) throws Exception{ String str = "java2s.com"; System.out.println(toHexString(str)); }//from ww w. java 2s. c o m public static String toHexString(String str) { byte[] byStr = str.getBytes(); return parseArr(byStr); } private static String parseArr(byte[] byStr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < byStr.length; i++) { sb.append("%" + Integer.toHexString(byStr[i])); } return sb.toString(); } }