ByteOrdering

ByteOrdering
is an option for BinaryRead, BinaryWrite, and related functions that specifies what ordering of bytes should be assumed for your computer system.

DetailsDetails

  • Possible settings for ByteOrdering are and .
  • corresponds to big endian (appropriate for PowerPC and many other processors); corresponds to little endian (appropriate for x86 processors).
  • corresponds to having the most-significant byte first; to having the least-significant byte first.
  • is the order obtained from IntegerDigits[n, 256].

ExamplesExamplesopen allclose all

Basic Examples (2)Basic Examples (2)

$ByteOrdering gives the byte ordering on this machine:

In[1]:=
Click for copyable input
Out[1]=

Create a file with a 32-bit integer:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
In[3]:=
Click for copyable input

Read the data from the file:

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input

Read the data with reverse byte ordering:

In[6]:=
Click for copyable input
Out[6]=

Recreate the correct interpretation using Mathematica functions:

In[7]:=
Click for copyable input
Out[7]=
In[8]:=
Click for copyable input
Out[8]=
In[9]:=
Click for copyable input
New in 5.2
New to Mathematica? Find your learning path »
Have a question? Ask support »