Function Resource

BitListToByteArray

Converts a list of bits to a byte array.

Contributed by: Arnoud Buzing

ResourceFunction["BitListToByteArray"][bits]

converts the list bits to a ByteArray.

Details and Options

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

Examples

Basic Examples

Create a list of bits:

In[1]:=
bits = RandomInteger[1, 160]
Out[1]=

Convert to a byte array:

In[2]:=
ba = ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/\
Function/BitListToByteArray"][bits]
Out[2]=

Compare the number of bytes needed to represent the expressions:

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