For logging purpose we are converting the logs to byte array and then to hex string. I want to get it back in a Java String, but I am not able to do so.
The hex string in log file looks something like
fd00000aa8660b5b010006acdc0100000101000100010000
How can I decode this?
Hex String – A Hex String is a combination of the digits 0-9 and characters A-F, just like how a binary string comprises only 0's and 1's. Eg: “245FC” is a hexadecimal string. Byte Array – A Java Byte Array is an array used to store byte data types only. The default value of each element of the byte array is 0.
toHexString and Integer. parseInt(hex, 16) to convert the String to Hex and vice versa. The idea is convert String <==> Decimal <==> Hex , for example char a , decimal is 97, hex is 61.
Using Hex
in Apache Commons:
String hexString = "fd00000aa8660b5b010006acdc0100000101000100010000"; byte[] bytes = Hex.decodeHex(hexString.toCharArray()); System.out.println(new String(bytes, "UTF-8"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With