INQUA Working Group on Data-Handling Methods

Newsletter 8: July 1992

BTA: BINARY TO ASCII CONVERSION PROGRAM

Eric C. Grimm
Illinois State Museum
Research and Collections Center
1920 South 10 1/2 Street
Springfield, IL 62703 USA
Email: grimm@denr1.igis.uiuc.edu

Introduction. BTA converts binary files to ASCII and the converted ASCII files back to binary. The program is useful for converting binary files to ASCII format for transfer by electronic mail. Both receiver and sender must have a copy of the program. The ASCII files, called BTA ASCII, consist entirely of ASCII characters, and can therefore be transferred by electronic mail utilities that understand ASCII. The program is written for IBM PC compatible computers by Eric C. Grimm and is available for free distribution and copying.

How the program works. The program first compresses the binary file and then writes out each byte in the compressed file as a two-character hexadecimal number. Compression will often reduce the original file in size by 50% or more. The final hexadecimal file will be approximately twice as large as the compressed file, and often about the size of the original file. The hexadecimal or BTA ASCII file consists entirely of ASCII characters. When the program converts BTA ASCII back to the original binary format, it first converts the two-character hexadecimal numbers to 8-bit bytes and then explodes the compressed file back to the original format. When converting the binary file to BTA ASCII, the program asks for a maximum file size. If the file is larger than this size, the program will write multiple files. The default maximum file size is 64 kb. The ASCII file will have the same root name as the original file, but the file extension will be a sequential number. For example, if the file PROG.EXE is converted to BTA ASCII, the file name would be PROG.001. If PROG.001 exceeds the maximum file size, file PROG.002 would be written, and so on. The first file in the sequence contains the original file name. Usage: BTA [FILENAME] [TOASC[II]|TOBIN[ARY]]. The filename and TOASC or TOBIN arguments are optional. See Fig. 1.




BTA
    The program will ask whether you are converting from binary to BTA
    ASCII or from BTA ASCII to binary and the filename to convert

BTA PROG.EXE
    The program will ask whether you are converting PROG.EXE to binary
    or to BTA ASCII.  BTA ASCII would be the only logical choice.

BTA PROG.EXE TOASC
    The program will convert PROG.EXE to BTA ASCII

BTA PROG TOBIN
    The program will convert PROG.001 to PROG.EXE

BTA PROG.001 TOBIN 
    The program will convert PROG.001 to PROG.EXE

Figure 1. Examples of program usage.
If you are converting from binary to BTA ASCII, type the complete filename, including the extension. If converting from BTA ASCII to binary, you do not need to type the extension (.001 is assumed). If more than one file exists (*.002, *.003,...), the sequential files will be read in their correct order. If you do not enter a file on the command line, the program will ask for the file name:

File to convert? (Press Enter for list)

If you press the Enter key with no filename or enter a wildcard (e.g. *.exe), the program will list the files in the current directory. See Fig. 2 and 3.




C:\>bta

BTA: Binary to ASCII Conversion Program
By Eric C. Grimm, 3 March 1991

[1] Convert binary file to BTA ASCII file
[2] Convert BTA ASCII file to binary file
Enter 1 or 2: 1
File to convert? (Press Enter for list) program.exe

Maximum size of output file in kb?
Enter a number 1-256 or press Enter for default: [Enter pressed]
Size of input file = 33136 bytes
Compressing file
Size of compressed file = 16167 bytes
Writing BTA ASCII file program.001
Total bytes written to BTA ASCII file(s) = 33180

Figure 2. Example of program session converting PROGRAM.EXE to BTA ASCII file PROGRAM.001






C:\>bta

BTA: Binary to ASCII Conversion Program
By Eric C. Grimm, 3 March 1991

[1] Convert binary file to BTA ASCII file
[2] Convert BTA ASCII file to binary file
Enter 1 or 2: 2
File to convert? (Press Enter for list) program

Converting program.001 to binary
16167 bytes written to binary compressed file
Exploding compressed file to program.exe

Figure 3. Example of program session converting PROGRAM.001 to PROGRAM.EXE
If you are converting from binary to BTA ASCII, you will be asked the maximum size of the output file in kb. (Ed: Some systems limit the size of email letters.)

The program reads the BTA ASCII file until it finds the starting point designated by a pair of curly braces "{{". Thus, introductory headers in the files do not need to be deleted before conversion (assuming a pair of curly braces does not occur in the header).

Error checking. When BTA writes a BTA ASCII file, it sums the bytes in the compressed file and writes this check sum at the end of the file. The numerical value of each byte is summed, not the number of bytes. When BTA reads a BTA ASCII file, it first checks that each ASCII character is a valid hexadecimal digit (0-9, A-F); it then converts the 2-character hexadecimal numbers to 8-bit bytes, which it adds for comparison with the check sum, thereby detecting virtually any error.

BTA ASCII file format. As shown in Fig. 4, the start of the first BTA ASCII file in a sequence is denoted by two curly braces "{{", followed by the name of the original file in quotes, followed by the hexadecimal codes. The end of the file is indicated by two closing curly braces "}}". If another file follows in the sequence (Fig. 5), the end of the file is indicated by two closing parentheses "))". The beginning of sequential files is indicated by two opening parentheses "((". Carriage return and line feed characters are inserted every 78 characters. Thus, the file consists of multiple lines 78 characters long. The check sum is written in brackets "[ ]" after the closing braces or parentheses of each file.




PROGRAM.001

{{"program.exe" 0006FEFDEF01008C1B8073005E4161F2840A95225200000067B75F0F5038D8
E7E220DFA40706625620FD422B7841AA60010004C5881420500C4931E40D9C3C72D29C41430704
D9B6EC9491E3A24D983120401C9113060E9AB42D4C796386CE9D3072CAB690670E9D326DE6B000
    [ many lines deleted here... ]
67C83DE226159B57FC9FFDCDEF6F7E7FF38CFFB3BFF9FD1BEDE609386E520A61482D01C85B03E7
B6FEC0080CFE02246EFF74F727C0C97D02C12E05000A680090A0800C000B0ACC1CDFA2F9039BA5
A2C0CD4A2880F30739ABA6800E00070AECEC036797B1053881F924E01F}}[190854 9]

Figure 4. Example of a BTA ASCII file smaller than the maximum file size



BIGPROG.001

{{"bigprog.exe" 0006FEFDEF01008C1C8077005E419192C4099522520036CB76BF1E00B1B06F
C742BEC9070025245E080000F50BADE0F3CFAA700200088A112940A0189262C81B3879E4A43983
860E08B26DD92923C7451A376340803822270C1C34695B98F2C60C9D3B61E4946D21CF1C3A65DA
    [ many lines deleted here... ]
8345CA2D84050DC1734BA0E4969BCF48B925C9330CB94556736B92987262B4890126A696185562
3E8925BC3D2EB700B2563338D6E2F1F6AAD373E79970360431B94AB35A325FC356C0278DAC1603
29E88279A60D3A48749D8A0881E2C4D5B82D9C8AAF92BA))[1935286]

BIGPROG.002

((36FCC92074EA006C098598EA06C534B54231E695A5CC31AF641B414020219C623A5AE8393F16
987DC06578A3852EED298650E2575F31D4D756426EEBB0E2FBCBB34619BBCEA1EC6C96CE3E441E
3551B26729479FD0E2D6B286E8A8640BC392C82A8844043924A28121D56F4714E04AC889FF09A8
    [ many lines deleted here... ]
ABB43FEEAF3E5501F3B009A902D67B7FBDF737BFBF79A8FFD9DFFCFEE6F737EFF43FFB9BDFDFFC
FEE699FE677FF3FB9BDFDFBCD2FFEC6F7E7FF3FB000490FD93D84D0BF0FA17D2FB40BD2E736015
D825BB0BB6416CB066F7410C10060030DBCC8940D2CD2701FF}}[299010]

Figure 5. Example of BTA ASCII file larger than maximum file size
How to get the program. Send a formatted diskette (5.25" or 3.5") and self-addressed diskette mailer to: Dr. Eric C. Grimm, Illinois State Museum, Research and Collections Center, 1920 South 10 1/2 Street, Springfield, IL 62703, USA.
Copyright © 1992 Eric C. Grimm
Home page
Newsletter 8 index
Author index
Subject index
WWW pages by K.D. Bennett