# XOR combination between the bits of a string

Given an integer n, we can construct $$2^n$$ strings of length n. We can take the first element for each of these strings and create a list. In total 'n' such lists are possible. But now I need to create lists that are the XOR combinations of the n lists created. If n is 3 and abc is the string then I need to calculate a$$\oplus$$b, a$$\oplus$$c, c$$\oplus$$b, a$$\oplus$$b$$\oplus$$c. How do I do this for a general n?

Here's the code so far...

n = 4; s = Tuples[{0, 1}, n]; a = Table[s[[i, j]], {j, 1, n}, {i, 1, 2^n}]

a gives the first four indices of all the strings. Now I need to calculate all the XOR combinations possible between these four lists.

• does Mod[Plus@##, 2] & @@@ Subsets[a, {2, n}] give what you need?
– kglr
Dec 8, 2020 at 7:26
• or (the same thing) Mod[Plus@##, 2] & @@@ Subsets[Transpose[s], {2, n}]?
– kglr
Dec 8, 2020 at 7:27
• or more concisely, Mod[Plus @@@ Subsets[Transpose[s], {2, n}], 2]
– kglr
Dec 8, 2020 at 7:47

Maybe

xOrCombinations[n_] := BitXor @@@ Subsets[Transpose @ Tuples[{0, 1}, n], {2, n}]

xOrCombinations[4] // MatrixForm // TeXForm


$$\left( \begin{array}{cccccccccccccccc} 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 \\ 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\ 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\ \end{array} \right)$$

Also

xOrCombinations2[n_] := Mod[Plus @@@ Subsets[Transpose@Tuples[{0, 1}, n], {2, n}], 2]

xOrCombinations2[4] == xOrCombinations[4]

 True