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);
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

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

Back To Top