4
$\begingroup$

Instead of

FromDigits[{2, 1, 1}, 2] 

with output 11, I want to insert a whole list of lists instead of {2,1,1}.

So if
lis = {{2, 1, 1}, {1, 1, 1}, {1, 0, 0}}
I want as output: {11, 7, 4} but FromDigits[lis, 2] does not work. How can I do it?

$\endgroup$
1
  • 2
    $\begingroup$ FromDigits[#, 2] & /@ lis is another way. $\endgroup$ – Fred Simons Apr 9 '18 at 7:01
8
$\begingroup$

The list of lists is read column-wise, so you need to transpose lis:

FromDigits[Transpose[lis], 2]

{11, 7, 4}

If the list is ragged then FromDigits[Transpose[PadRight[lis]], 2]

$\endgroup$
1
  • $\begingroup$ This will not work though if lis is a ragged list... $\endgroup$ – Henrik Schumacher Apr 9 '18 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.