Wednesday, May 23, 2007

Ascii to Hex in C#

try
{
int iTemp = 0;
string sTemp = "";
string strHex;
foreach (char c in txtKeyA.Text)
{
iTemp = c;
strHex = String.Format("{0:x2}", (uint)System.Convert.ToUInt32(iTemp.ToString()));
// MessageBox.Show(strHex);
sTemp = sTemp + strHex;
}
txtKeyA.Text = sTemp;
this.btnToHex.Enabled = false;
this.btnToAscii.Enabled = true;
}
catch(Exception eE)
{
// MessageBox.Show(eE.ToString());
MessageBox.Show("Failed to convert!!! Please check your input format!");
}

No comments: