       List of bits to String

• To: mathgroup at smc.vnet.net
• Subject: [mg28726] List of bits to String
• From: "Helge Andersson" <helgea at inoc.chalmers.se>
• Date: Fri, 11 May 2001 03:38:44 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Hello,

In an earlier posting Murray Eisenberg wrote

I have a list consisting of binary digits, of a given length, e.g.,
{0, 1, 1, 0, 1}.  I wish to convert this to a _string_ consisting of
those digits: "01101".  How can this be done?

Several people responded quick and fast. There were several approaches,
some of them were fast and elegante, others not.

I performed a competition with some of the postings.
Two factors were considered, Length of the coding and the timing.
Here is the result of the competition listed in order of performance.
As you can see, the Length of coding happend to coincide with
the timing even if not in proportion.

The List of binary digits was called dli

In:=
dli=Random[Integer,{0,1}]&/@Range;
___________________________________________
In:=
Timing[ToString[FromDigits[dli]];]

Out=
{0.13 Second,Null}

In:=
Timing[StringJoin[ToString/@dli];]

Out=
{0.531 Second,Null}

In:=
Timing[Apply[StringJoin,ToString/@dli];]

Out=
{0.551 Second,Null}

In:=
g[{x_,y_,z___}] :=  { StringJoin[ToString[x], ToString[y]], z };
f[ lst_ ]:=Nest[g, lst, Length[lst]-1];

In:=
Timing[f[dli];]

Out=
{32.437 Second,Null}

```

• Prev by Date: Re: Plotting
• Next by Date: RE: Plotting
• Previous by thread: Re: Re: list of bits to string
• Next by thread: Computer Science with Mathematica Book