I'm not sure exactly what you are referring to here but I am assuming that you are receiving data from an api call that is a byte array, into a string, and you want to create a hex string that represents the byte data. If so, then this should do it depending on which Encoding will work for you:
// test string string theString = System.Text.ASCIIEncoding.Unicode.GetString( new byte[] {15, 16, 1, 29, 210, 44, 5, 255} ); // issue here is whether the Unicode or ASCIIEncoding is correct or neither byte[] data = System.Text.UnicodeEncoding.Unicode.GetBytes(theString); System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (byte b in data) { if (b < 16) b.ToString("0"); sb.Append(b.ToString("X")); } An issue I see with your logic, if I am understanding you correctly, is that a byte array containing 0 and 10 does not hex encode to "0A", but rather to "000A". Otherwise you would hex decode "0A" to a single element byte array of conataining 10. Chad On Wed, 24 Sep 2003 05:52:42 -0400, Randy Collins <[EMAIL PROTECTED]> wrote: >I am calling a 3rd party win32 api function that is returning binary data >from a mainframe into a StringBuilder type parameter. This function also >takes a length parameter to tell it how big the StringBuilder buffer is. > >My question is, how to I format this binary data as a hex string? That is, >if the buffer contains two bytes, a binary 0 and a binary 10 (decimal), I >return "0A". > >Thanks > >=================================== >This list is hosted by DevelopMentorŪ http://www.develop.com >NEW! ASP.NET courses you may be interested in: > >2 Days of ASP.NET, 29 Sept 2003, in Redmond >http://www.develop.com/courses/2daspdotnet > >Guerrilla ASP.NET, 13 Oct 2003, in Boston >http://www.develop.com/courses/gaspdotnet > >View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorŪ http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com