Dave's Brain

Browse - programming tips - java convert a string to hex

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();
	}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: