If you were to swap input/outputs you you'd have
$1\to 0$
$2 \to \frac 12$
$3\to \frac 34$
$4\to \frac 78$
And for any $k\to m$ we'd have $k+1$ to $1 - \frac {1-m}2$.
It's easy to so the pattern that the denominator is always $2^{k-1}$ and the numerator is $ ({2^{k-1} -1})$. and we have $k \to \frac {2^{k-1}-1}{2^{k-1}} = 1 - \frac 1{2^{k-1}}$.
So $k$ is our output and $1-\frac 1{2^{k-1}}$ is our input we have
So we have input expressed in terms of output. We want output expressed in terms of input.
Let $k$ be the output and $j$ be the input.
We have $j= 1-\frac 1{2^{k-1}}$. We need to reverse that to get $k = \text{something to do with }j$.
So.... solve for $k$.
$j = 1-\frac 1{2^{k-1}}$
$j-1 = -\frac 1{2^{k-1}}$
$\frac 1{2^{k-1}}=1-j$
$2^{k-1} = \frac 1{1-j}$
$\log_2 2^{k-1} = \log_2 \frac 1{1-j}$
$k-1 = \log_2\frac 1{1-j}$
$k = 1+ \log_2\frac 1{1-j} = 1-\log_2 (1-j)$.
Not that the requires $0 \le j < 1$.
If To do an example if $j = \frac {31}{32}$ we get
$k = 1-\log_2 (1-\frac {31}{32})=1-\log_2(1-\frac {31}{32})=1-\log_2(\frac 1{32})=1-\log_2 2^{-5} = 1-(-5) = 6$. Just as we expected!
And if we have an arbitrary value. So $j=\frac 23$ (meaning we'd expect $j$ to be between $2$ and $3$ [as $\frac 12 < \frac 23 < \frac 34$]) we have
$k = 1-\log_2(1-\frac 23)=1-\log_2 \frac 13 = 1-\log_2 3^{-1} = 1+\log_2 3 = 1+ \frac {\log_{10} 3}{\log_{10}2} = 1+\frac {0.47712125471966243729502790325512}{0.47712125471966243729502790325512} = 1+ 1.5849625007211561814537389439478=2.5849625007211561814537389439478$