Browse - Programming Tips - How do I convert a String into its equivalent ASCII hex characters?

Date: 2011sep28
Language: Java

Q.  How do I convert a String into its equivalent ASCII hex characters?

A.  Here's a function that efficiently does that:

String stringToHex(final String in) { StringBuilder out = new StringBuilder(in.length() * 2); for (int i = 0; i < in.length(); i++) { out.append(Integer.toHexString(in.charAt(i))); } return out.toString(); }