Bin to Ascii file converter
Freeware

"Counting in binary is just like counting in decimal if you are all thumbs."    — Glaser and Way.
On this page:

History

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.

History:
v1.0 — 1999/06/22 — Original release
v1.3 — 1999/12/16 — Modified to allow any number of formats (saves them in INI files
v1.4 — 2001/06/12 — Added byte swapping option
v1.5 — 2001/06/27 — Corrected byte swapping bug, added string support, repeat numbers, much faster display, unlimited string size...
v1.6 — 2001/06/28 — Error checking on output format strings added
v1.7 — 2002/03/22 — Minor internal things
v1.8 — 2002/10/04 — Added Y, H and U for unsigned byte, short and long.
v1.9 — 2002/11/04 — Added custom string delimiter output.
v1.0 — 2005/07/14 — Added command line program OD2.exe similar to Unix Octal Dump (see below)
v1.10 — 2011/12/09 — Added more explicit sizes, 8-byte longs and various levels of swapping



[BinToAscii1.png]
Screenshot of BinToAscii in action

Purpose

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.


[BinToAscii2.gif]
BinToAscii user interface

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 7E
converted 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



Format specification

Details of the format specification: sequence of [B|Y|S|H|L|U|F|D|C|I][number]

B
Reads one signed byte (value: -128 to 127)
Y
Reads one unsigned byte (value: 0 to 255)
S
Reads one signed short integer (value: -32768 to 32767), two bytes
H
Reads one unsigned short integer (value: 0 to 65535), two bytes
L
Reads one signed long integer (value: -2147483648 to 2147483647), 4 bytes
U
Reads one unsigned long integer (value: 0 to 4294967295), 4 bytes
T
Reads one signed int64 (value: -9223372036854775808 to 9223372036854775807), 8 bytes
N
Reads one unsigned int64 (value: 0 to 18446744073709551616), 8 bytes
F
Reads one IEEE float, 4 bytes. Note that there exists other formats of float than IEEE produced by other processors (TI floats for instance). This program cannot currently read them.
D
Reads one IEEE double, 8 bytes.
C
Reads one character (same as one byte, except that it will be displayed as a character instead of a value).
Note that there are at least 3 standards for defining character strings: Fortran uses fixed length buffers and if the actual string is shorter, the rest is filled with spaces; C uses a terminating 0 value in unlimited memory (making for very easy buffer overruns), Pascal uses a fixed buffer (255 characters) with a preceding byte containing the actual length. So basically for reading a 30 character string, from Fortran you'd do C30, from C you can't or try C30 or the buffer size, from Pascal you'd do BC255.
I
Ignore one byte (it's read from the file but not displayed). I1024 will ignore one Kb.
Space
Spaces inserted between the format characters are ignored, they are allowed for readability.

Bugs, features and tips


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...


Octal Dump 2

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...



[Support.gif]
Support my site: make a donation, buy images, use associate services
Download: Yes ! Yes ! Yes ! Where is it ? I want to download BinToAscii and OD2 executables now (8Mb) !

Note: the source code of both BinToAscii and OD2 is available on gitlab.

This freeware written with LabWindows/CVI.