Here is sample code. It may be good example of what you need to do.
That code is not tested!
void Foo(string inputFilePath, string outputFilePath)
{
try
{
if (File.Exists(inputFilePath))
{
using (BinaryWriter bw = new BinaryWriter(File.Create(inputFilePath)))
{
using (BinaryReader br = new BinaryReader(File.Open(inputFilePath, FileMode.Open, Encoding.ASCII)))
{
int pos = 0;
int length = (int)br.BaseStream.Length;
while (pos < length)
{
var endOfLine = "\r\n";
bw.Write(String.Format("0x{0:X}{1}", (int)br.ReadChar()), endOfLine);
pos += sizeof(int);
}
}
}
}
else
{
throw new FileNotFoundException("Input file not found!",inputFilePath);
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
}
;)