Monday, August 24, 2009

Encoded Hex String to Text with C#

byte[] data = FromHex ( "4D657373616765204C696E652032" );
s = Encoding.ASCII.GetString ( data );
public static byte[] FromHex ( string hex )
{

byte[] raw = new byte[hex.Length / 2];
for (int i = 0; i < raw.Length; i++)
{ raw[i] = Convert.ToByte ( hex.Substring ( i * 2, 2 ), 16 ); }
return raw;
}