/ Published in: C#
Simple program to convert a BIN file to CSV. Demonstrates .net usage of: * command-line parameters, * binary and text file access * looping thru a file using the catch (EndOfStreamException) construct * byte-swapping for endianness
I used this to convert binary MICR data to a CSV for use in Excel
Expand |
Embed | Plain Text
using System; using System.Collections.Generic; using System.Text; using System.IO; namespace ConvertMicrBinToCsv { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Expecting 2 parameters: a .bin file and a .csv file."); return; } foreach (string arg in args) { Console.WriteLine(arg); } try { while (true) { UInt16 val = br.ReadUInt16(); UInt16 i = (UInt16)System.Net.IPAddress.NetworkToHostOrder((Int16)val); // endianness sw.WriteLine("{0}", i); } } catch (EndOfStreamException e) { // caught and ignored. } finally { br.Close(); sw.Close(); } return; } } }
You need to login to post a comment.
