Dave's Brain

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(); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.