I have an API that sends data back & forth between client and server. On the client side there is a parser that takes this data and puts it into a properties file.
I have converted the string data on the server side to a hex integer to avoid getting in trouble with my parser because I split my data on characters like ";" and "_". So if my data contains any of those characters it will cause problems with my parser.
server send: SC;4b6579_56616c7565;4b65790a4e65776c696e65_56616c75650a4e65776c696e65;4b65795f556e64657273636f7265_56616c75655f556e64657273636f7265
client received: SC;4b6579_56616c7565;4b65790a4e65776c696e65_56616c75650a4e65776c696e65;4b65795f556e64657273636f7265_56616c75655f556e64657273636f7265
So some sample data would be
String key = "4b6579";
String value = "56616c7565";
int hexKey = Integer.parseInt(key, 16);
int hexValue = Integer.parseInt(value, 16);
How do I turn my hexKey
and hexValue
into strings?
The result should be as below:
4b6579
converts to the wordKey
56616c7565
converts to the wordValue
EDIT:
The answer was found here: Convert a String of Hex into ASCII in Java