$|\mathbb N^{\mathbb N}| = |2^\mathbb N|$ by finding a bijection I was trying to find a direct proof that $|\mathbb N^{\mathbb N}| = |2^\mathbb N|$, by finding a bijection between the two sets. The idea that came to mind was to start with the sequence of natural numbers. Each natural number would be 'translated' in a sequence of zeroes of the length given by the natural number. A  1 would be added to the sequence obtained, and all the 01 sequences thus obtained would be concatenated in the order dictated by the original sequence of naturals. However, this would run into problems, since all complete 01 sequences thus obtained would end on 1, so that the function from $\mathbb N^{\mathbb N}$ to $2^\mathbb N$ would not be surjective.
I turned to Stack Exchange for advice and found out that the post Cardinality of the set of all natural sequences is $2^{\aleph_0}$ contained the same solution, except that ones were switched for zeroes and vice versa. Of course, this could not work either: all 01 sequences obtained end on 0.
As a workaround to the problem, I would propose the function as described above, except that the last natural number in the original series would now be translated in its binary form, and no 0 or 1 added. I think that would result in a bijection. Could that be right? Would there be other possibilities?
Edit: I am now convinced that the approach I proposed cannot work either. The function is not injective. At first I thought that the last part of the 01 sequence corresponding to the last natural number of the original sequence would be identifiable by its starting with 11 (one 1 stemming from the previous number, the other from the binary form of the last natural in the sequence - except when that would be 0). I now realize that 11 may occur within the binary form itself.
Therefore, still at a loss...
 A: There is clearly an injection $2^{\mathbb{N}} \to \mathbb{N}^{\mathbb{N}}$, and the graph of a function provides an injection $\mathbb{N}^{\mathbb{N}} \to 2^{\mathbb{N} \times \mathbb{N}}$. Composing this with some injection (or even bijection) $\mathbb{N} \times \mathbb{N} \to \mathbb{N}$ yields an injection $\mathbb{N}^{\mathbb{N}} \to 2^{\mathbb{N}}$. Now recall that the proof of the Cantor-Schröder-Bernstein theorem is constructive. It explicitly produces a bijection $\mathbb{N}^{\mathbb{N}} \cong 2^{\mathbb{N}}$ from our two injections. It is a good exercise to write it down.
Edit: Here are some details. Given injections $f : A \hookrightarrow B$, $g : B \hookrightarrow A$, one recursively  defines sets by $C_0 = A \setminus g(B)$, $C_{n+1}:=g(f(C_n))$, and takes their union $C=\cup_{n \geq 0} C_n$. Then, the map
$$h : A \to B,~a \mapsto \left\{\begin{array}{cc} f(a) & a \in C \\ g^{-1}(a) & a \notin C \end{array}\right.$$
is a bijection: this is the content of the Cantor-Schröder-Bernstein theorem. In our case, $f : \mathbb{N}^{\mathbb{N}} \hookrightarrow 2^{\mathbb{N}}$ is defined by $a \mapsto \{(2n+1) \cdot 2^{a(n)} : n \in \mathbb{N}\}$; here I have chosen the bijection $\mathbb{N} \times \mathbb{N} \to \mathbb{N}$, $(x,y) \mapsto (2x+1) 2^y$; and I identify $2^{\mathbb{N}}$ with the power set of $\mathbb{N}$. On the other hand, $g : 2^{\mathbb{N}} \hookrightarrow \mathbb{N}^{\mathbb{N}}$ simply maps $T\subseteq\mathbb{N}$ to the characteristic function $\chi_T$. If $a \notin C_0$, i.e. $a \in g(B)$, then $g^{-1}(a) = a^{-1}(\{1\})$. So we only have to describe $C \subseteq \mathbb{N}^{\mathbb{N}}$ in order to make the bijection $h : \mathbb{N}^{\mathbb{N}} \to 2^{\mathbb{N}}$ explicit.
A: The function you are describing in your post is a bijection from the set of infinite sequences of natural numbers to the set of infinite binary sequences.
To get a bijection from the set of finite sequences of natural numbers to the finite binary sequences, you can use the unique factorization of $\mathbb{N}$: every finite sequence $(a_1,a_2,\cdots,a_n)$ corresponds with a positive natural number $q = 2^{a_1} 3^{a_2} \cdots p_n^{a_n}$. Now look at the binary representation of q + 1, with the first digit removed (it's always a 1), and you have your desired correspondence.
A: I am thinking of this mapping:
for $A = (a_1,a_2,\cdots,a_n,\cdots) \in \mathbb{N}^\mathbb{N}$,
1) if $a_1 > 0$, then map $A$ to:
$$ (a_1 \mbox{ copies of } 1, \, a_2 \mbox{ copies of } 0, \, \cdots , a_n \mbox{ copies of } (n \mod 2), \,), \cdots$$
2) if $a_1 = 0$, and there exists a $k \in \mathbb{N}$ such that $a_k > 0$, then (suppose $k$ be the first one) map $A$ to:
$$ (k-1 \mbox{ copies of } 0, \,a_k \mbox{ copies of } 1, \, a_{k+1} \mbox{ copies of } 0, \, \cdots , a_{k+n-1} \mbox{ copies of } (n \mod 2), \,), \cdots$$
3) map $(0,0,\cdots)$ to itself.
It seems to be a bijection.
A: Martin Brandenburg has shown you how such a bijection may be constructed; here is an argument that the more straightforward approaches (translating each individual number onto a binary codeword, possibly depending on some internal state like the parity of the index in corindo's approach) are likely doomed. Suppose we want to compute a bijection $f:2^\mathbb{N}\to\mathbb{N}^\mathbb{N}$, which reads its input one bit at a time and occasionally (when the end of a codeword has been reached) outputting a number. A natural approach would be a form of extended final automaton:
$A=(Q,q_0,F,\delta,\epsilon)$, where $Q$ is a finite set of locations, $q_0\in Q$ is the initial location, $F\subseteq Q$ is a set of accepting locations (where we recognize that we have reached the end of a codeword), $\delta:Q\times 2\to Q$ is the transition function, and $\epsilon:Q\times2\times\mathbb{N}\to\mathbb{N}$ keeps track of a numerical value associated with the current prefix. A state of this machine is a pair $(q,n)\in Q\times\mathbb{N}$, and upon reading $i\in 2$, we transition from $(q,n)$ to $(q',n')$ with $q'=\delta(q,i)$ and $n'=\epsilon(q,i,n)$. We start in the state $(q_0,0)$ and output $n$ whenever $q\in F$.
For example, for the encoding suggested by OP, we have just two locations $q_0,q_1$, with $F=\{q_1\}$. The transition functions are


*

*$\delta(q_0,0)=q_0, \epsilon(q_0,0,n)=n+1$: while we read $0$s, increment the current value.

*$\delta(q_0,1)=q_1, \epsilon(q_0,1,n)=n$: we read a $1$, and output the current value.

*$\delta(q_1,0)=q_0, \epsilon(q_1,0,n)=1$: start reading the next codeword.

*$\delta(q_1,1)=q_1, \epsilon(q_1,1,n)=0$: empty codeword, output $0$.


The problem is the following: in any such automaton,


*

*Either there exists a cycle which does not contain an accepting state, in which case we stop getting outputs (like the loop given by $\delta(q_0,0)=q_0$ in the example, representing the fact that $000\dots$ does not correspond to any number), or

*there is no such cycle, but then there are only finitely many paths between accepting states, and therefore at any time only finitely many numbers we may output next. Thus the map is not surjective.


What this means is that for any such bijection, there is no bound on the amount of information we need to remember about the history of the computation.
