Re: FromDigits[{135,21}] -> 1371 (??!!)
- To: mathgroup at smc.vnet.net
- Subject: [mg53740] Re: [mg53725] FromDigits[{135,21}] -> 1371 (??!!)
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Wed, 26 Jan 2005 04:36:14 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Zak, please see below: >-----Original Message----- >From: Zak Seidov [mailto:seidovzf at yahoo.com] To: mathgroup at smc.vnet.net >Sent: Tuesday, January 25, 2005 11:03 AM >To: mathgroup at smc.vnet.net >Subject: [mg53740] [mg53725] FromDigits[{135,21}] -> 1371 (??!!) > >Can anyone please explain what happens, >if "Digits" actually are "integers": >FromDigits[{3,2}] >32(!) >FromDigits[{13,2}] >132 (!!) >FromDigits[{135,2}], >1352 (!!!) >FromDigits[{1355078,9}] >13550789 (!!!!!!!) >it's OK above, >but: >FromDigits[{135,21}] >1371 (??!!) >FromDigits[{13,23}] >153 (??!!) >FromDigits[{3,23}] >53 (??!!) > The answer is simple, if we ask how FromDigits should work, i.e. let's implement (part of) it: In[2]:= fromdigits[l : {__Integer?NonNegative}, base : (_Integer?Positive) : 10] := Fold[#2 + #1*base &, 0, l] This is how it works. In[3]:= fromdigits[{3, 2}] Out[3]= 32 In[4]:= fromdigits[{13, 2}] Out[4]= 132 In[5]:= fromdigits[{135, 2}] Out[5]= 1352 In[6]:= fromdigits[{1355078, 9}] Out[6]= 13550789 In[7]:= fromdigits[{135, 21}] Out[7]= 1371 In[8]:= fromdigits[{13, 23}] Out[8]= 153 In[9]:= fromdigits[{3, 23}] Out[9]= 53 >And how to get integer 1323 from list {13,23}? > e.g. In[10]:= fromdigits[{13, 23}, 100] Out[10]= 1323 In[11]:= FromDigits[{13, 23}, 100] Out[11]= 1323 This might not be usable for your application, if not >So, or there is a better way: >li={135,42};FromDigits[Flatten[{IntegerDigits[li[[1]]],IntegerD >igits[li[[2]]]}]]-> >13542 > this or something equivalent In[12]:= FromDigits[Join @@ IntegerDigits /@ {13, 23}] Out[12]= 1323 >Many thanks, >and if you please send copy to >seidovzf at yahoo.com >Zak > >PS I use M4. >M5 also gives >FromDigits[{135,21}] >1371 (??!!) > > Of course, it should! -- Hartmut Wolf