Function Repository Resource:

ByteArrayToBitList

Source Notebook

Converts a byte array to a list of bits

Contributed by: Arnoud Buzing

ResourceFunction["ByteArrayToBitList"][ba]

converts ByteArray ba to a list of bits.

Details and Options

The output typically requires 64 times more memory than the input.

Examples

Basic Examples (4) 

Create a byte array:

In[1]:=
ba = ByteArray[RandomInteger[{0, 255}, 20]]
Out[1]=

Convert to individual bits:

In[2]:=
bits = ResourceFunction["ByteArrayToBitList"][ba]
Out[2]=

Compare the number of bytes needed to represent the expressions:

In[3]:=
ByteCount /@ {bits, ba}
Out[3]=

For larger bit arrays the relative memory expansion does approach a factor of 64:

In[4]:=
ba = ByteArray[RandomInteger[{0, 255}, 2000]];
bits = ResourceFunction["ByteArrayToBitList"][ba];
Divide @@ N[ByteCount /@ {bits, ba}]
Out[6]=

Publisher

Arnoud Buzing

Version History

  • 1.0.0 – 25 September 2019

License Information