Basic Examples (4)
Basic Examples
(4)
Create a list of bits:
In[44]:=
bits=RandomInteger[1,160]
Out[44]=
{0,0,0,1,1,1,0,1,1,0,1,0,1,1,0,1,1,1,0,1,0,1,0,1,1,1,1,0,1,1,1,1,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,0,0,0,0,0,0,1,1,1,0,1,0,1,1,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,1,0,1,1,0,0,1,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,1,1,0,1}
Convert to a byte array:
In[45]:=
ba=[bits]
Out[45]=
ByteArray
Compare the number of bytes needed to represent the expressions:
In[32]:=
ByteCount/@{bits,ba}
Out[32]=
{1392,116}
For larger bit arrays the relative memory compression does approach a factor of 64:
In[57]:=
bits=RandomInteger[1,16000];ba=[bits];Divide@@N[ByteCount/@{bits,ba}]
Out[59]=
61.1374