SOLUTIONS

MATHEMATICA IMPORT/EXPORT FORMAT
Binary
Sequence of binary data objects.
Binary format.
Stores a uniform sequence of simple or compound data types.
Binary format.
Stores a uniform sequence of simple or compound data types.
 Import reads raw binary data as a sequence of elementary or compound data types.
 Export generates binary files from uniform lists of elementary or compound data types.
Import and ExportImport and Export
 Import["file", "Binary"] imports any binary file as a list of bytes.
 Export["file", list, "Binary"] exports a list of bytesize integers to a binary file.
 The format must be specified when importing or exporting raw binary files.
 Import["file", {"Binary", elem}] or Import["file", elem ] imports the specified element from a binary file.
 Import["file", {"Binary", {elem_{1}, elem_{2}, ...}}] imports multiple elements.
 Export["file", expr, {"Binary", elem}] creates a binary file by treating expr as specifying element elem.
 See the reference pages for full general information on Import and Export.
 ImportString and ExportString support raw binary files.
 BinaryRead and BinaryWrite can be used for reading from or writing to streams of raw binary data.
ElementsElements
 General Import elements:

"Elements" elements and options available in this file "Rules" full rules for each element and option "Options" rules for options, properties, and settings  Data representation elements:

"Bit" zeros and ones "Byte" integers in the range 0 to 255 "Character8" 8bit characters "Character16" 16bit characters "Integer8" 8bit signed integers "Integer16" 16bit signed integers "Integer24" 24bit signed integers "Integer32" 32bit signed integers "Integer64" 64bit signed integers "Integer128" 128bit signed integers "UnsignedInteger8" 8bit unsigned integers "UnsignedInteger16" 16bit unsigned integers "UnsignedInteger24" 24bit unsigned integers "UnsignedInteger32" 32bit unsigned integers "UnsignedInteger64" 64bit unsigned integers "UnsignedInteger128" 128bit unsigned integers "Real32" IEEE singleprecision numbers "Real64" IEEE doubleprecision numbers "Real128" IEEE quadprecision numbers "Complex64" IEEE singleprecision complex numbers "Complex128" IEEE doubleprecision complex numbers "Complex256" IEEE quadprecision complex numbers  By default, Import and Export use the element.
 For any data representation element type, Import["file", type] can be used as a shorthand for Import["file", {"Binary", type}].
 Import of real numbers returns Infinity for IEEE "infinity", and Indeterminate for IEEE "notanumber".
 Trailing bytes are ignored if the size of the imported file is not a multiple of the data size.
OptionsOptions
 General option:

ByteOrdering 1 what byte ordering to use  Import option:

"HeaderBytes" 0 how many bytes to skip at the beginning of the file  Data representation option:

"DataFormat" Automatic specifies a compound object as a list of basic data types  With a setting , Import and Export interpret a raw binary file as a sequence of objects of the form .
 Import["file", "Binary", "DataFormat">{"Character8", "Integer32"}] reads file as an alternating sequence of 8bit characters and 32bit integers.
ExamplesExamplesopen allclose all
Basic Examples (2)Basic Examples (2)
Convert a string of characters to a list of bytevalued integers:
In[1]:= 
Out[1]= 
The format specification can be omitted when importing elementary data types:
In[2]:= 
Out[2]= 
Export pairs of integers and reals to a binary sequence of 8bit integers and doubleprecision reals:
In[1]:= 
Out[1]= 
Convert the previous output back to an array of numbers:
In[2]:= 
Out[2]= 
Verify that each number pair was converted to bytes:
In[3]:= 
Out[3]= 
New in 5.1  Last modified in 6
Mathematica 9 is now available!
New to Mathematica?
Find your learning path »
Have a question?
Ask support »