Last active
December 11, 2015 08:38
-
-
Save dmamills/4574231 to your computer and use it in GitHub Desktop.
Daily programmer #117 easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.reddit.com/r/dailyprogrammer/comments/16jiuq/011413_challenge_117_easy_hexdump_to_ascii/ | |
// Usage: programname.exe textfile.txt | |
using System; | |
using System.Linq; | |
using System.IO; | |
namespace DailyProgrammer117 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length >= 1) | |
{ | |
string filename = args[0]; | |
if (File.Exists(filename)) | |
{ | |
var file = File.ReadAllBytes(filename).ToList(); | |
var counter = 16; | |
var lc = 0; | |
foreach (var f in file) | |
{ | |
if (counter == 16) | |
{ | |
Console.WriteLine(); | |
counter = 0; | |
lc++; | |
Console.Write(String.Format("{0}", lc.ToString("X").PadLeft(5, '0'))); | |
} | |
Console.Write(string.Format(" {0}", f.ToString("X").PadLeft(2,'0'))); | |
counter++; | |
} | |
} | |
else | |
{ | |
Console.WriteLine("File '{0}' not found", filename); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment