Advertisement
Willcode4cash

String ToHex -> Hex ToString

Sep 22nd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. public string ConvertStringToHex(string asciiString)
  2. {
  3.     string hex = "";
  4.     foreach (char c in asciiString)
  5.     {
  6.         int tmp = c;
  7.         hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
  8.     }
  9.     return hex;
  10. }
  11.      
  12. public string ConvertHexToString(string HexValue)
  13. {
  14.     string StrValue = "";
  15.     while (HexValue.Length > 0)
  16.     {
  17.         StrValue += System.Convert.ToChar(System.Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
  18.         HexValue = HexValue.Substring(2, HexValue.Length - 2);
  19.     }
  20.     return StrValue;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement