Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Return the hexadecimal format of a plain text string. * * @param strValue * @return */ public static String stringToHex(String strValue) { byte byteData[] = null; int intHex = 0; String strHex = ""; String strReturn = ""; try { byteData = strValue.getBytes("ISO8859-1"); for (int i = 0; i < byteData.length; i++) { intHex = (int) byteData[i]; if (intHex < 0) intHex += 256; if (intHex < 16) strHex += "0" + Integer.toHexString(intHex).toUpperCase(); else strHex += Integer.toHexString(intHex).toUpperCase(); } strReturn = strHex; } catch (Exception ex) { ex.printStackTrace(); } return strReturn; } }