Wolfram Computation Meets Knowledge

ByteArrayPlot

Contributed by: Richard Hennigan (Wolfram Research)

Visualize the contents of binary data

ResourceFunction["ByteArrayPlot"][bytes]

visualizes the binary data in a ByteArray bytes.

ResourceFunction["ByteArrayPlot"]["file"]

reads the contents of "file" into a ByteArray for visualization.

ResourceFunction["ByteArrayPlot"][expr]

equivalent to ByteArrayPlot[BinarySerialize[expr]].

ResourceFunction["ByteArrayPlot"][expr,n]

visualizes up to n bytes of expr.

Details and Options

Files can be given as a String,CloudObject,File, or URL.
ByteArrayPlot[expr] is equivalent to ByteArrayPlot[expr,1024].

Examples

Basic Examples

Use the function:

In[1]:=
ResourceFunction["ByteArrayPlot"][ByteArray[Range[0, 255]]]
Out[2]=

More Examples

Scope

Retrieve the ResourceFunction:

In[3]:=
ResourceFunction["ByteArrayPlot"]
Out[3]=

Retrieve the ResourceObject:

In[4]:=
ResourceObject["ByteArrayPlot"]
Out[4]=

When the content is PrintableASCIIQ, it will appear as plain text:

In[5]:=
file = Export["hello.txt", "Hello world"]
Out[5]=
In[6]:=
ResourceFunction["ByteArrayPlot"][file]
Out[7]=

When content is mixed, the non-printable bytes are rendered as color coded hex values:

In[8]:=
file = Export["hello.mx", "Hello world"]
Out[8]=
In[9]:=
ResourceFunction["ByteArrayPlot"][file]
Out[10]=

Generalizations & Extensions

Visualize the binary data contained in a file:

In[11]:=
ResourceFunction["ByteArrayPlot"][FindFile["ExampleData/spikey2.png"]]
Out[12]=

Only view the first 10 bytes:

In[13]:=
ResourceFunction["ByteArrayPlot"][
 FindFile["ExampleData/spikey2.png"], 10]
Out[14]=

View the contents of a CloudObject:

In[15]:=
expr = {"here's a string", Range[0, 255, 32], <|"a" -> f[x], sym -> "Hello world"|>}
Out[15]=
In[16]:=
co = CloudExport[expr, "WXF"]
Out[16]=
In[17]:=
ResourceFunction["ByteArrayPlot"][co]
Out[18]=

View the bytes of the WXF format directly:

In[19]:=
ResourceFunction["ByteArrayPlot"][expr]
Out[20]=

Applications

Compare binary formats:

In[21]:=
expr = {"here's a string", Range[0, 255, 32], <|"a" -> f[x], sym -> "Hello world"|>}
Out[21]=
In[22]:=
ResourceFunction["ByteArrayPlot"][ExportByteArray[expr, "WXF"]]
Out[23]=
In[24]:=
ResourceFunction["ByteArrayPlot"][ExportByteArray[expr, "MX"]]
Out[25]=
In[26]:=
ResourceFunction["ByteArrayPlot"][ExportByteArray[expr, "WDX"]]
Out[27]=

Properties and Relations

Packed arrays are aptly named:

In[28]:=
a1 = Range[20];
a2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
In[29]:=
Developer`PackedArrayQ[a1]
Out[29]=
In[30]:=
Developer`PackedArrayQ[a2]
Out[30]=
In[31]:=
ResourceFunction["ByteArrayPlot"][a1]
Out[32]=
In[33]:=
ResourceFunction["ByteArrayPlot"][a2]
Out[34]=

Possible Issues

By default, only the first 1024 bytes are shown:

In[35]:=
ResourceFunction["ByteArrayPlot"][FindFile["ExampleData/turtle.jpg"]]
Out[36]=

Use the second argument to view more:

In[37]:=
ResourceFunction["ByteArrayPlot"][
 FindFile["ExampleData/turtle.jpg"], 1500]
Out[38]=

Resource History