# Row function to join together binary number elements

I am trying to join entries of binary numbers at the lowest level of a nested list, e.g.

testlist = {{{100, 100}, {101, 101}}, {{110, 110}, {111, 111}}, {{111,
100}, {111, 110}}, {{101, 111}, {110, 101}}}


Using the Row function seems to work

rowlist = Table[Row[testlist[[i, j]]], {i, 4}, {j, 2}]


with the resulting output displayed as

{{100100,101101},{110110,111111},{111100,111110},{101111,110101}


which is the desired result. However when I check the first entry at the third level, i.e.  rowlist[[1,1,1]] I get {100, 100} which suggests that this is merely a change of display rather than fundamentally changing the list, as does the output from rowlist when pasted here

{{Row[{100, 100}], Row[{101, 101}]}, {Row[{110, 110}],
Row[{111, 111}]}, {Row[{111, 100}],
Row[{111, 110}]}, {Row[{101, 111}], Row[{110, 101}]}}


How can I change the list so that the first entry at the deepest level is rowlist[[1,1]]=100100 ?

• Map[{10^Floor[Log10[#[[2]]] + 1], 1} . # &, testlist, {2}] Commented Apr 13, 2022 at 3:38

testlist = {{{100, 100}, {101, 101}}, {{110, 110}, {111, 111}}, {{111,
100}, {111, 110}}, {{101, 111}, {110, 101}}}

Map[StringJoin,
Map[ToString, testlist, {-1}]
, {-2}
]

{{"100100", "101101"}, {"110110", "111111"}, {"111100",
"111110"}, {"101111", "110101"}}


The inner Map applies to the leaves and converts the entries using ToString. Depending on the entries, some zero padding may be required in the general case.

The outer Map applies one level up and joins the strings produced in the first step using StringJoin.

EDIT

If you want to convert these strings (at leaf level now) to a decimal number, then add another Map. A string can be passed to FromDigits directly and uses base 10 as default.

Map[FromDigits,
Map[StringJoin,
Map[ToString, testlist, {-1}
]
, {-2}
]
, {-1}
]


Let's define a function that joins together two of the entries:

join[{x_, y_}] := ToExpression[StringJoin[{ToString[x], ToString[y]}]];


Now we can use this function to answer your question. With testlist as you have defined it above, you can get your desired form by:

Partition[join /@ Flatten[testlist, 1], 2]
{{100100, 101101}, {110110, 111111}, {111100, 111110}, {101111, 110101}}

Map[FromDigits @* Flatten @* IntegerDigits, testlist, {2}]

{{100100, 101101}, {110110, 111111}, {111100, 111110}, {101111, 110101}}


## 1

{100, 100} -> 100100

f[{x_,y_}] = x*10^IntegerLength[x] + y;
f[{100,100}];


## 2

g = Map[f]
g[{{100, 100}, {101, 101}}]


get {100100,101101}

## 3

 {{{100, 100}, {101, 101}}, {{110, 110}, {111, 111}}, {{111,
100}, {111, 110}}, {{101, 111}, {110, 101}}} // Map[g]

{{100100, 101101}, {110110, 111111}, {111100, 111110}, {101111, 110101}}


just step by step.

list =
{{{100, 100}, {101, 101}}, {{110, 110}, {111, 111}},
{{111, 100}, {111, 110}}, {{101, 111}, {110, 101}}};


Using Replace at level 2

Replace[list, {a_, b_} :> ToExpression[ToString[a] <> ToString[b]], {2}]


{{100100, 101101}, {110110, 111111}, {111100, 111110}, {101111, 110101}}

list =
{{{100, 100}, {101, 101}}, {{110, 110}, {111, 111}},
{{111, 100}, {111, 110}}, {{101, 111}, {110, 101}}};


Using ReplaceAll:

list /. v_?VectorQ :> ToExpression["" <> ToString /@ v]


Result:

{{100100, 101101}, {110110, 111111}, {111100, 111110}, {101111, 110101}}

Or using ReplaceAll, IntegerDigits and FromDigits:

list /. v_?VectorQ :> FromDigits@*Join @@ IntegerDigits[v]


Result:

{{100100, 101101}, {110110, 111111}, {111100, 111110}, {101111, 110101}}