how to scale an integer up and down by multiples of 4... with a twist I apologize for the title; I don't even know what I am asking for is really called.
I have two series of numbers (array indices really):
{0,1,2,3}

AND
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

These sets can increase by multiples of 4 (4, 16, 64, 256, etc).
What I am trying to do is figure out how to "scale" an index to its lower multiple, and higher multiple equivalents. There is a catch though. Consider the following crude drawing:

Each set is to be treated as a square, and when scaling, the result should be in the square region. 
Few examples: 


*

*scaling 5 down should result in 0

*scaling 10 down should result in 3

*scaling 11 down should result in 3

*scaling 12 down should result in 2

*scaling 3 down should result in 1


scaling up will never be exact I understand, so for that, I am content with finding the "top left" number. for instance:


*

*scaling 1 up results in 2

*scaling 2 up results in 8

*scaling 3 up results in 10


I have been at this for a few days now, and every time I find a solution, I realize I only found a solution for a certain "resolution". I just can't seem to figure out the core pattern. 
Does this have something to do with quadratics?
 A: Convert to $4$-bit binary; take the first and third bits.
$$2\left \lfloor \frac n 8\right\rfloor+\left\lfloor \frac{n\bmod4}2\right\rfloor$$
To reverse, $$8\left \lfloor \frac n 2\right \rfloor+2(n\bmod2)$$
In the next stage $(64\to16)$, convert to six-bit binary and drop bits $3$ and $6$.
$$4\left \lfloor \frac n {16}\right \rfloor+\left \lfloor \frac {n\bmod8}2 \right \rfloor\\
16\left \lfloor \frac n 4\right \rfloor+2(n\bmod4)
$$
A: In general, let's say you have a $2^{n+1} \times 2^{n+1}$ array
indexed according to the scheme you have shown, that is,
if the columns and rows are both numbered $\{0, \ldots, 2^{n+1} - 1\}$,
then the "index" in column $i$ of row $j$ is $k_{n+1}(i,j) = i + j \cdot 2^{n+1}$.
And let's say you want to map the cells of this array to the cells of
a $2^n \times 2^n$ array where the "index" in column $i$ of row $j$ is 
$k_n(i,j) = i + j \cdot 2^n$. 
The first half of your question is, given an index $k_{n+1}$ of a cell in the
first array, you want to know the index $k_n$ of the cell in the second
array to which the first cell is mapped.
Notice that for any index $k_m(i,j)$ of a $2^m \times 2^m$ array,
we can find $i$ and $j$ via these two formulas:
\begin{align}
i &\equiv k_m(i,j)  \pmod{2^m}, \\[6pt]
j &= \left\lfloor \frac{k_m(i,j)}{2^m} \right\rfloor.
\end{align}
Now choose an arbitrary index $k_{n+1}$ from the first array.
This is a number in the range $\{0, \ldots, 4^{n+1} - 1\}$.
If we divide $k_{n+1}$ by $2$, discarding any fractional part,
we end up with a number $k' = \left\lfloor \frac12 k_{n+1} \right\rfloor$
in the range $\{0, \ldots, 2\cdot4^n - 1\}$.
Moreover, 
$k' \equiv k_n \pmod{2^n},$
where $k_n$ is the index we want to find.
So $k' \equiv i \pmod{2^n},$ 
where the cell we are trying to map $k_{n+1}$ to is in column $i$
of the smaller array.
The only reason we cannot use $k'$ as the new index 
is that it "indexes" each row of the smaller array twice.
That is, either
$$\left\lfloor \frac{k'}{2^n} \right\rfloor = 2j
\qquad \text{or} \qquad \left\lfloor \frac{k'}{2^n} \right\rfloor = 2j+1,$$
where the cell we are trying to map $k_{n+1}$ to is in row $j$
of the smaller array.
But if we divide by $2$ again, discarding any fractional part, we get $j$.
Equivalently, we can just divide by $2$ again, discarding the remainder,
and then 
$$j = \left\lfloor \frac12 \left\lfloor \frac{k'}{2^n} \right\rfloor \right\rfloor
 = \left\lfloor \frac{k'}{2^{n+1}} \right\rfloor 
 = \left\lfloor \frac{\left\lfloor \tfrac12 k_{n+1} \right\rfloor}{2^{n+1}} \right\rfloor 
 = \left\lfloor \frac{k_{n+1}}{2^{n+2}} \right\rfloor. 
$$
Using $p \bmod q$ to denote the integer $r$ such that $r \equiv p \pmod q$
and $0 \leq r < q$, we can say that the cell indexed by $k_{n+1}$
is mapped to the cell in column $i$, row $j$ of the smaller array where
\begin{align}
i &= \left\lfloor \tfrac12 k_{n+1} \right\rfloor \bmod 2^n, \\[4pt]
j &= \left\lfloor \frac{k_{n+1}}{2^{n+2}} \right\rfloor,
\end{align}
and therefore
$$
k_n = \left(\left\lfloor \frac{k_{n+1}}{2} \right\rfloor \bmod 2^n\right)
      + 2^n \left\lfloor \frac{k_{n+1}}{2^{n+2}} \right\rfloor.
$$
To reverse the mapping, by doubling $k_n$ we get an index of the
larger array that is in the correct column, but at the end of each
row we need to "skip" a row of the larger array.
So the formula is
$$
k_{n+1} = 2 k_n + 2^{n+1} \left\lfloor \frac{k_n}{2^n} \right\rfloor.
$$
