Skip to content

Instantly share code, notes, and snippets.

@haeky
Created July 3, 2013 14:32
Show Gist options
  • Save haeky/5918457 to your computer and use it in GitHub Desktop.
Save haeky/5918457 to your computer and use it in GitHub Desktop.
Example of a hex to string conversion and string to hex.
//DECODE -> HEX TO STRING
String wHexString = "THIS IS A CONVERSION TEST";
byte[] wRaw = new byte[wHexString.Length / 2];
for (int i = 0; i < wRaw.Length; i++)
{
wRaw[i] = Convert.ToByte(wHexString.Substring(i * 2, 2), 16);
}
String iStack = Encoding.ASCII.GetString(wRaw);
//ENCODE -> STRING TO HEX
Char[] wStack = iStack.ToCharArray();
foreach (Char wLetter in wStack)
{
int wNumber = Convert.ToInt32(wLetter);
wStackString += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(wNumber.ToString()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment