Convert ASCII values from hex to characters

by Prashant 31. May 2009 00:46

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); 

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags:

C# | Code Snippets

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Visit blogadda.com to discover Indian blogs Computers Blogs

About Me

Name of authorPrashant Khandelwal.
Programmer and tech enthusiast. More...

Feeds Subscribe Twitter Facebook Google Plus Linked In Delicious

My Visual Studio Achievements

Badges

Month List

Blog Stats

321,792 Hits

Adverts

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Creative Commons License