Suppose I have the sequence $\langle x_1, ..., x_n \rangle \in \mathbb{N}^n$ that gets encoded to the binary string $$ \begin{matrix} \underbrace{11...1} & 0 & \underbrace{11...1} & 0 & \underbrace{11...1} & 0 & & ... & 0 & \underbrace{11...1}\\ x_1 \text{ times} & & x_2 \text{ times} & & x_3 \text{ times} & & & & & x_n \text{ times} \end{matrix} $$
For example, the sequence $\langle 3, 2, 1 \rangle$ gets encoded to $11101101$.
I have been trying to figure out a function $f: \mathbb{N}^n \to \mathbb{N}$ that takes the input sequence and outputs the number that is conversion of the binary encoding of the sequence according to the following rule.
If $E = b_1 b_2 ... b_l$ is a binary encoding, then the number that is the conversion of the binary encoding is $\sum_{i=0}^{l-1}2^i b_i$.
For example the binary encoding $11101101$ from the previous example gets converted to $1+2+4+0+16+32+0+128 = 183$.
So, going by the previous examples, my desired function should output $f(3, 2, 1) = 183$.
Here is what I have so far.
I know the length of the binary encoded string of the sequence $\langle x_1, ... x_n \rangle$ should be $n - 1 + \sum_{i=1}^n x_i$. Let this length be denoted by $l$. So suppose the sequence $\langle x_1, ... x_n \rangle$ gets encoded to $E = b_1 ... b_l$.
Then, if $E = 11...1$, the value of $f(x_1, ..., x_n) = \sum_{i = 1}^l{2^i} = 2^l-1$. If we subtract off the value of what all the $0$s in the sequence should have contributed, we can get the real value of $f(x_1, ..., x_n$.
Now as far as I can tell, the $k$th $0$ in the binary encoding could have been $2^{k - 1 + \sum_{i=1}^k{x_i}}$. There are $n-1$ $0$s in the binary encoding, so the sum of what the $1$st, $2$nd, ..., $n-1$th $0$ could have been is $$ \sum_{i=1}^{n-1}{2^{i - 1 + \sum_{j=1}^i{x_j}}}. $$
Therefore, the true value of $f(x_1, ..., x_n)$ is the value of what all the $0$s in the binary encoding could have amounted to, subtracted from the value of what it should be if the binary encoding was all $1$s.
That is, $$ f(x_1, ..., x_n) = 2^l-1 - \sum_{i=1}^{n-1}{2^{i - 1 + \sum_{j=1}^i{x_j}}}. $$
I want to try this out on the first example.
So, by the first example, we know $f(3, 2, 1) = 183$. Then let's check if my formula works.
\begin{align*} f(x_1, ..., x_n) &= 2^l-1 - \sum_{i=1}^{n-1}{2^{i - 1 + \sum_{j=1}^i{x_j}}}\\ &= 2^{n - 1 + \sum_{i=1}^n x_i} - 1 - \left( {2^{1 - 1 + x_1}} + {2^{2 - 1 + x_1 + x_2}} \right)\\ &= 2^{3 - 1 + x_1 + x_2 + x_3} - 1 - \left( 2^{x_1} + 2^{1 + x_1 + x_2} \right)\\ &= 2^8 - 1 - 2^3 - 2^6\\ &= 183 \end{align*}
So it seems to work.
My question is: This is pretty ugly, and I think my way of arriving to the solution is very long-winded. Is there an easier/more elegant solution to this problem? This is a small part of a proof I am doing for a computability theory assignment, and I doubt this should have taken this long.