Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

To Decode String From Hex

DZone's Guide to

To Decode String From Hex

·
Free Resource
// To decode string from hex


	public static String decodeStringFromHex(String hexText) {

		String decodedText = null;
		String chunk = null;

		if (hexText != null && hexText.length() > 0) {
			int numBytes = hexText.length() / 2;

			byte[] rawToByte = new byte[numBytes];
			int offset = 0;
			// int bCounter = 0;
			for (int i = 0; i < numBytes; i++) {
				chunk = hexText.substring(offset, offset + 2);
				offset += 2;
				rawToByte[i] = (byte) (Integer.parseInt(chunk, 16) & 0x000000FF);
			}
			decodedText = new String(rawToByte);
		}
		return decodedText;
	}
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}