Program © 1998-2017 Guillaume Dargaud. Free use and distribution.
Last updated on 2013/04/19
"Counting in binary is just like counting in decimal if you are all thumbs." — Glaser and Way.
This program is a simple generic binary to ascii file converter. It reads files containing integers or floating points numbers written according to a given format, then writes them all as comma/tab separated ascii in a text file. The binary files structure should be an optional header followed by a succession of records.
This page gets a lot of hits through various search engine keywords, so let me emphasize a few things that this program is not:
Although it bears similarities with the tools above, this program is useful only for converting (scientific) data written in sequential records. Say somebody sends you a bunch of files and says: "T'was written with a fortran program on a Unix box, they have a succession of 1 million records of two REAL*4 and two COMPLEX*8..." You don't want to write a program just to read them before importing in Excel or whatever (as if Excel could actually read a million records, hah!). The answer is at the end of the page...
You select the files you want to convert with the [Select Files] button. Obviously, all the files should have the same format. You can try to convert files for which you ignore the format or the length of the records; just try one format after another, the prog displays the resulting header and first record of the first file. If the files are simple (succession of floats for instance), and you know more or less what to expect, you should find a way after a few tries.
Two strings specify the kind of data contained in the (optional) header and the successive records. For instance: "BLLLF" means one byte, followed by 3 long integers (signed), followed by one 4 byte floating point number (it is the same as "B L3 F", numbers allow you to repeat the last letter and spaces are ignored). You can specify several different file formats (here we have 'custom', 'MET and 'USA' which are the meteorological data formats for which I originally wrote this program), they are saved when you exit the program. Click on [New] to add one or [Clear] to remove the one currently selected. In case of error in the format string, the Led turns red and a '?' appears at the offensive characters.
When you press [Read All], all the files you have selected get converted from the beginning and merged to a text file that you can save wherever you want.
This program was designed to convert scientific data in a quick and easy way (so you can view them in Excel for instance), it's in no way meant to replace a program reading directly the binary files which will always be much faster. This program is not optimized for speed. You can get about a user interface control by right-clicking it.
Example: the binary file containing the following 57 bytes:
0A D0 07 40 39 D2 FF 11 C7 31 42 6C BB D5 A7 3B BD 94 7E 0A D0 07 40 39 D2 FF 11 C7 31 42 6C BB D5 A7 3B BD 94 7E 0A D0 07 40 39 D2 FF 11 C7 31 42 6C BB D5 A7 3B BD 94 7Econverted with the following format string: "BSLFD" will output the following:
10, 2000, -3000000, 44.4, 5.56e+301 10, 2000, -3000000, 44.4, 5.56e+301 10, 2000, -3000000, 44.4, 5.56e+301
Details of the format specification: sequence of
The answer to the Fortran riddle of paragraph 4 is "L F2 D4 L". Yes, Fortran saves an integer containing the length of the record at the beginning and end of each record. Hah! And you most likely need to enable the byte swapping option too...
Once you know the format of your files, it may be a pain to spend time launching BinToAscii each time you need to convert a new one. Unix traditionally contains a command line utility called
od (octal dump) that does something similar. I wrote a similar command line program called
od2.exe which uses the same syntax as od but outputs its results only once, which makes more sense if you want to convert the file instead of reverse-engineer it.
Just type od2 /? on a command line to learn how it works. Here's the source code for those interested in compiling it on any C compiler. Unfortunately the format specification is different between BinToAscii and OD2...
This freeware written with LabWindows/CVI.