using System;
using System.IO;
class HexDump {
public static void Main(string[] astrArgs) {
Stream stream = new FileStream("c:\\a.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] abyBuffer = new byte[16];
long lAddress = 0;
int count;
while ((count = stream.Read(abyBuffer, 0, 16)) > 0) {
ComposeLine(lAddress, abyBuffer, count);
lAddress += 16;
}
}
public static void ComposeLine(long lAddress, byte[] abyBuffer, int count) {
Console.WriteLine(String.Format("{0:X4}-{1:X4} ", (uint)lAddress / 65536, (ushort)lAddress));
for (int i = 0; i < 16; i++) {
Console.WriteLine((i < count) ? String.Format("{0:X2}", abyBuffer[i]) : " ");
Console.WriteLine((i == 7 && count > 7) ? "-" : " ");
}
Console.WriteLine(" ");
for (int i = 0; i < 16; i++) {
char ch = (i < count) ? Convert.ToChar(abyBuffer[i]) : ' ';
Console.WriteLine(Char.IsControl(ch) ? "." : ch.ToString());
}
}
}