From adac1ea9dbd843e5e6d1391c04b004513828f688 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 21 Sep 2016 01:54:09 +0100 Subject: [PATCH] Add method to get hexadecimal printout of a byte array. --- ArrayFill.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ArrayFill.cs b/ArrayFill.cs index 7c6be86cb..772e36684 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -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(); + } } }