MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: list of digits to string


"Murray Eisenberg" <murraye at attbi.com> wrote in message
news:a8rgcs$b3s$1 at smc.vnet.net...
> How do I convert a list of bits, say {0, 1, 1, 0, 0}, to a corresponding
> character string, "01100"?  Just for bits, the expression
>
>   StringJoin[lis /. {0 -> "0", 1 -> "1"}]
>
> does what I want.  But, more generally, how do I do the same with
> arbitrary digits?  The expression similar to the above but for all 9
> digits 0, 1, 2, ..., 9 seems overly long.  Is there an easier way?


Murray,
Initial zeros are a problem. Here are two ways:

    lst= Join[{0},Table[Random[Integer,{0,9}],{10000}]];

    s1=StringDrop[ToString[FromDigits[Prepend[lst,1]]],1];//Timing

        {1.1 Second,Null}

    s2=StringJoin@@ToString/@lst;//Timing

        {2.69 Second,Null}

    s1===s2

    True

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: Plot with disks
  • Next by Date: Is it possible?
  • Previous by thread: Re: list of digits to string
  • Next by thread: RE: Re: list of digits to string