2015-10-05 18:58:13 +01:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
The Disc Image Chef
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Filename : PrintHex.cs
|
|
|
|
|
|
Version : 1.0
|
|
|
|
|
|
Author(s) : Natalia Portillo
|
|
|
|
|
|
|
|
|
|
|
|
Component : Helpers
|
|
|
|
|
|
|
|
|
|
|
|
Revision : $Revision$
|
|
|
|
|
|
Last change by : $Author$
|
|
|
|
|
|
Date : $Date$
|
|
|
|
|
|
|
|
|
|
|
|
--[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Prints a byte array as hexadecimal in console.
|
|
|
|
|
|
|
|
|
|
|
|
--[ License ] --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
it under the terms of the GNU General Public License as
|
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
Copyright (C) 2011-2014 Claunia.com
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
//$Id$
|
|
|
|
|
|
using System;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
using DiscImageChef.Console;
|
2015-10-05 18:58:13 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class PrintHex
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void PrintHexArray(byte[] array, int width)
|
|
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine(ByteArrayToHexArrayString(array, width));
|
2015-10-05 18:58:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string ByteArrayToHexArrayString(byte[] array, int width)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
|
|
int subcounter = 0;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
for(long i = 0; i < array.LongLength; i++)
|
2015-10-05 18:58:13 +01:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(counter == 0)
|
2015-10-05 18:58:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0:X16} ", i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(subcounter == 3)
|
2015-10-05 18:58:13 +01:00
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
sb.Append(" ");
|
2015-10-05 18:58:13 +01:00
|
|
|
|
subcounter = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
sb.Append(" ");
|
2015-10-05 18:58:13 +01:00
|
|
|
|
subcounter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("{0:X2}", array[i]);
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(counter == width - 1)
|
2015-10-05 18:58:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
counter = 0;
|
|
|
|
|
|
subcounter = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
counter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|