BBS: Inland Empire Archive Date: 04-13-92 (21:03) Number: 167 From: RICHARD VANNOY Refer#: NONE To: PAUL MILLSAPS Recvd: NO Subj: Help with writing garbage Conf: (2) Quik_Bas
PM>Just wanted to jump in here and ask about binary files. What are thes, PM>and how are they used. The snappy, witty answer is that all files are binary files since the definition means the ability to access any single byte in the file. But that wouldn't help you much. Here is a short lesson on file types I put together for someone a while back: File Types 101 by Richard Vannoy. Definitions: Field: A particular type of information in a file. Common field names would be phone number, name, address, or date. Record: The sum of the fields for one person, place or thing. Field 1: Name: Richard <----- Together, these three Field 2: Phone: 777-1212 <----- fields make one Field 3: Birthday: 04\26\60 <----- record. There are generally three types of files most commonly used today. They are sequential, random access and binary. Sequential, as the name implies, means that data is written to the file in sequence, or one after the other, so if I write the name and phone numbers of a few friends in a sequential file, it might look like: (The commas are called delimiters. They are put in by you or the program to separate each piece of data) Sam,777-5155,George,123-4567,Bill,323-1212 Notice that all of the information (fields and records) are slammed together and that there is no way to tell where the name Bill starts without reading the file from the beginning. If Richard is the 100th name in the list, we have to READ the first 99 names/phone numbers to get to it. In a random access file, the fields are defined to a specific length and any spaces not used are filled with blanks. This allows each record to be the exact same size. Like.. Name: 10 bytes |Richard | Phone: 8 bytes |777-1212| Now we have a record length of 18 bytes, no matter how long the data is, so lets write the same info as above to a file.. Sam 777-5155George 123-4567Bill 323-1212 | | | Note how a new record starts every 18 bytes, so we can predict where every record is going to start. And we don't need separaters since we know exactly where each record and each field starts. Not only that, if we know that Richard's info is in the 100th record, we can go directly to it since the record length is constant. Because of this predictabil- ity, which transforms to SPEED when it is time to find stuff, random access records are well suited to storing and retriev- ing large quantities of data. These are the two most common storage techniques, but there are many more! One, called Indexed Sequential Access Method (ISAM) is stored somewhat like a sequential file, but is accessed through an indexing system, which gives it the main advantage of sequential files (packing info tightly) and also the main advantage of random access files (FAST recovery). Binary files... Well ALL files are binary files to the extent that any DOS file can be opened in the binary mode. By binary, we generally mean we want the ability to see, get or write to any byte in the file. In the examples above, if we wanted to know the three digit prefix of Bill's phone number, with both sequential and random access, we would have to read in the whole number, and pull out the first three digits, but with binary, we could go right to the applicable bytes and grab just the 323 prefix. Another common use of binary files is when we want to a machine language (EXE, COM) file and perhaps correct or change just a few bytes. Also, if you have no idea what is in a file, opening it in binary lets you look around easier and snoop the file. > MegaMail 2.1b #0:AAAAA:American Association Against Acronym Abuse . --- WM v2.01/91-0012 * Origin: Com-Dat BBS Hillsboro, OR. HST (503) 681-0543 (1:105/314)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET