sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | http://1 |
sitelink4 | http://ko |
sitelink5 | http://www.experts-exchange.com/Programm...69882.html |
sitelink6 | http://sitelink1 |
Question
I want to convert a Hex String to String.
Example
input : "41424344"
Example output : "ABCD"
Answer
public static String hexToString(String input, int groupLength) {
StringBuilder sb = new StringBuilder(input.length() / groupLength);
for (int i = 0; i < input.length() - groupLength + 1; i += groupLength) {
String hex = input.substring(i, i + groupLength);
sb.append((char) Integer.parseInt(hex, 16));
}
return sb.toString();
}
Question
String object to Hex string
Answer
public String stringToHex(String st) {
StringBuffer sb = new StringBuffer();
for(int i = 0; i<st.length(); i++){
int ch=(int)st.charAt( i );
String hs = "00"+Integer.toHexString( ch );
sb.append(hs);
}
return sb.toString();
}