Convert ASCII values from hex to characters

Convert ASCII values from hex to characters
This C# code takes in a list of ASCII values (hexadecimal) and shows the actual characters behind, thus converting hex values to strings.
1. // An object storing the hex value
2. string HexValue = "4765656B7065646961";
3. // An object storing the string value
4. string StrValue = "";
5. // While there's still something to convert in the hex string
6. while (HexValue.Length > 0)
7. {
8.     // Use ToChar() to convert each ASCII value (two hex digits) to the actual character
9.    StrValue += System.Convert.ToChar(System.Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
10.    // Remove from the hex object the converted value
11.     HexValue = HexValue.Substring(2, HexValue.Length - 2);
12. }
13. // Show what we just converted
14. MessageBox.Show(StrValue);

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top