Function Repository Resource:

ByteArrayPlot

Source Notebook

Visualize the contents of binary data

Contributed by: Richard Hennigan (Wolfram Research)

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 (1) 

Use the function:

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

Scope (4) 

Retrieve the ResourceFunction:

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

Retrieve the ResourceObject:

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

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

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

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

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

Generalizations & Extensions (2) 

Visualize the binary data contained in a file:

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

Only view the first 10 bytes:

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

View the contents of a CloudObject:

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

View the bytes of the WXF format directly:

In[14]:=
ResourceFunction["ByteArrayPlot"][expr]
Out[14]=

Applications (1) 

Compare binary formats:

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

Properties and Relations (1) 

Packed arrays are aptly named:

In[19]:=
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[20]:=
Developer`PackedArrayQ[a1]
Out[20]=
In[21]:=
Developer`PackedArrayQ[a2]
Out[21]=
In[22]:=
ResourceFunction["ByteArrayPlot"][a1]
Out[22]=
In[23]:=
ResourceFunction["ByteArrayPlot"][a2]
Out[23]=

Possible Issues (2) 

By default, only the first 1024 bytes are shown:

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

Use the second argument to view more:

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

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 15 August 2018

License Information