Created
July 3, 2013 14:32
-
-
Save haeky/5918457 to your computer and use it in GitHub Desktop.
Example of a hex to string conversion and string to hex.
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
//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