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.

// An object storing the hex value
string HexValue = "4765656B7065646961";
// An object storing the string value
string StrValue = "";
// While there's still something to convert in the hex string
while (HexValue.Length > 0)
{
    // Use ToChar() to convert each ASCII value (two hex digits) to the actual character
    StrValue += Convert.ToChar(Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
    // Remove from the hex object the converted value
    HexValue = HexValue.Substring(2, HexValue.Length - 2);
}
// Show the converted value
MessageBox.Show(StrValue); 
comments powered by Disqus