Convert byte data to string output, as in a hex editor

Im looking for a method that will return a string representation of byte data in the same way as a hex editor. It should have one parameter byte[]and returns stringas follows: Like it should be

This method should handle escape characters, zeros, and properly align text. I want to use it in Debug.WriteLine(). Please help me with this! Thank!

Update: OK. Thanks to everyone guys. Here is a link to a ready-to-use solution http://illegalargumentexception.blogspot.fr/2008/04/c-file-hex-dump-application.html Darina Dimitrova

+3
source share
2 answers

ToString:

public static string ToString(byte[] buffer)
{
    return BitConverter.ToString(buffer);
}
+2

:

  byte[] b1 = ...

  string h = System.Text.Encoding.UTF8.GetString(b1);
+1