Re: list of digits to string
- To: mathgroup at smc.vnet.net
- Subject: [mg33774] Re: list of digits to string
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 16 Apr 2002 03:50:22 -0400 (EDT)
- References: <a8rgcs$b3s$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"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