Difference between "ASCII" and "Binary" formats in PETSc

smilingbuddha picture smilingbuddha · Dec 22, 2010 · Viewed 9k times · Source

I wanted to know what the difference is between binary format and ASCII format. The thing is I need to use PETSc to do some matrix manipulations and all my matrices are stored in text files.

PETSc has different set of rules for dealing with these formats. I don't know what these formats are, let alone what format my text file is.

Is there a way to convert one format to another?

This is an elementary question; a detailed answer will really help me in understanding this.

Answer

OmnipotentEntity picture OmnipotentEntity · Dec 22, 2010

To answer your direct question, the difference between ASCII and binary is semantics.

ASCII is binary interpreted as text. Only a small subset of binary code can be interpreted as intelligible characters (decimal 32-126) everything else is either a special character (such as a line feed or a system bell or something else entirely.) Larger characters can be letters in other alphabets.

You can interpret general binary data as ASCII format, but if it's not ASCII text it may not mean anything to you.

As a general rule of thumb, if you open your file in a text editor (such as notepad, not such as microsoft word) and it seem to consist entirely of letters or primarily of letters, numbers, and spaces, then your file can probably be safely interpreted as ASCII. If you open your file in your text editor and it's noise it's probably needs to be interpreted as raw binary.

I am not very familiar with the program you're asking about, were I in your situation I would consult the documentation of the program to figure out what format the "binary" data stream is supposed to be in. There should be a detailed description or an included utility for generating your binary data. If you generated the data yourself it's probably in ASCII format.