Add method to get hexadecimal printout of a byte array.

This commit is contained in:
2016-09-21 01:54:09 +01:00
parent bf98ed9ffc
commit 9a87166daf
2 changed files with 57 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
// ****************************************************************************/
using System;
using System.Text;
namespace DiscImageChef
{
@@ -61,6 +62,20 @@ namespace DiscImageChef
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
}
public static string ByteArrayToHex(byte[] array)
{
return ByteArrayToHex(array, false);
}
public static string ByteArrayToHex(byte[] array, bool upper)
{
StringBuilder sb = new StringBuilder();
for(long i = 0; i < array.LongLength; i++)
sb.AppendFormat("{0:x2}", array[i]);
return upper ? sb.ToString().ToUpper() : sb.ToString();
}
}
}