public static String hexStringToAsciiString(final String hexString){
  final String realText=(hexString.length() % 2) == 0 ? hexString : "0" + hexString;
  final StringBuilder stringBuilder=new StringBuilder();
  for (int i=0; i < realText.length(); i+=2) {
    final char c1=realText.charAt(i);
    final char c2=realText.charAt(i + 1);
    if (!isHexCharacter(c1) || !isHexCharacter(c2)) {
      throw new IllegalArgumentException("Error: Invalid hex string");
    }
    final char code=(char)((Character.digit(c1,16) << 4) + Character.digit(c2,16));
    stringBuilder.append(isPrintableCharacter(code) ? code : ".");
  }
  return stringBuilder.toString();
}

public static String hexStringToAsciiString ( final String hexString ) { final String realText = ( hexString . length ( ) % 2 ) == 0 ? hexString : "0" + hexString ; final StringBuilder stringBuilder = new StringBuilder ( ) ; for ( int i = 0 ; i < realText . length ( ) ; i += 2 ) { final char c1 = realText . charAt ( i ) ; final char c2 = realText . charAt ( i + 1 ) ; if ( ! isHexCharacter ( c1 ) || ! isHexCharacter ( c2 ) ) { throw new IllegalArgumentException ( "Error: Invalid hex string" ) ; } final char code = ( char ) ( ( Character . digit ( c1 , 16 ) << 4 ) + Character . digit ( c2 , 16 ) ) ; stringBuilder . append ( isPrintableCharacter ( code ) ? code : "." ) ; } return stringBuilder . toString ( ) ; }
converts a hex to ascii . if the hex string has an odd number of characters , a 0 is added at the end of the string . example : 414141 is converted to aaa
