Created
June 4, 2012 13:15
-
-
Save Dynyx/2868299 to your computer and use it in GitHub Desktop.
String to hex / Hex to string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string ConvertStringToHex(string asciiString) | |
{ | |
string hex = ""; | |
foreach (char c in asciiString) | |
{ | |
int tmp = c; | |
hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())); | |
} | |
return hex; | |
} | |
public string ConvertHexToString(string HexValue) | |
{ | |
string StrValue = ""; | |
while (HexValue.Length > 0) | |
{ | |
StrValue += System.Convert.ToChar(System.Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString(); | |
HexValue = HexValue.Substring(2, HexValue.Length - 2); | |
} | |
return StrValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment