Re: FromDigits[{135,21}] -> 1371 (??!!)

• To: mathgroup at smc.vnet.net
• Subject: [mg53744] Re: FromDigits[{135,21}] -> 1371 (??!!)
• From: Veli Peltola <velipeltola at hotmail.com>
• Date: Wed, 26 Jan 2005 04:36:20 -0500 (EST)
• Organization: Helsinki Television
• References: <ct561v\$e8b\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Zak Seidov wrote:
> Can anyone please explain what happens,
> if "Digits" actually are "integers":
...
> FromDigits[{135,21}]
> 1371 (??!!)
> FromDigits[{13,23}]
> 153 (??!!)
> FromDigits[{3,23}]
> 53 (??!!)

Writing numbers like 1592 is in a sense a shorter way of writing

1*10^3 + 5*10^2 + 9*10^1 + 2*10^0

Mathematica's FromDigits uses a formula like this. This means

FromDigits[{13,23}] = 13*10 + 23 = 153

The elements in the list don't even have to be natural numbers.
For example:

FromDigits[{1,-1}] = 10 - 1 = 9
FromDigits[{a,b}] = 10a + b

> And how to get integer 1323 from  list {13,23}?
>
> So, or there is a better way:
> li={135,42};FromDigits[Flatten[{IntegerDigits[li[[1]]],IntegerDigits[li[[2]]]}]]->
> 13542

Using IntegerDigits and FromDigits together is probably the easiest way
to go. If you need to do this several times, you could define a function
for it.

fromIntegers[l_] := FromDigits[Flatten[IntegerDigits /@ l]]

Now for example:

fromIntegers[{12,34,567}] -> 1234567

Hope this helps.

--
Veli Peltola

```

• Prev by Date: Re: Form of a linear equation
• Next by Date: Re: simplifying inside sum, Mathematica 5.1
• Previous by thread: Re: FromDigits[{135,21}] -> 1371 (??!!)
• Next by thread: Re: FromDigits[{135,21}] -> 1371 (??!!)