All These Things That I've Done

Apply the programming model to everyday programming problems
posts - 83, comments - 71, trackbacks - 4

My Links

News


View Gianluca Carucci's profile on LinkedIn

Tag Cloud

Archives

Post Categories

Image Galleries

Blogs

Links

Convertire un array di byte in stringa esadecimale

Visto che ne ho avuto bisogno, pubblico un piccolo snippet per risolvere il problema:

private static string ConvertToHex(string msg)
{
  if (msg == null || msg == string.Empty)
  {
  return string.Empty;
  }
   System.Text.StringBuilder sb =
new StringBuilder();
   byte[] bmsgs = ASCIIEncoding.ASCII.GetBytes(msg); 
   foreach (byte inByte in bmsgs)
  {
    sb.Append(String.Format("{0:X2} ",inByte).Trim());
  }
  return sb.ToString();
}

Print | posted on venerdì 29 aprile 2005 16:48 | Filed Under [ C# ]

Powered by:
Powered By Subtext Powered By ASP.NET