Speed Up Access to Fractal-Like Array I'm trying to speed up the following function in c++:  

void num_to_xy(int num, int *x, int *y):
    *x = (cl &amp; 0x03) | ((cl &amp; 0x10) &gt;&gt; 2) | ((cl &amp; 0x40) &gt;&gt; 3) | ((cl &amp; 0x100) &gt;&gt; 4) | ((cl &amp; 0x400) &gt;&gt; 5) | ((cl &amp; 0x1000) &gt;&gt; 6) | ((cl &amp; 0x4000) &gt;&gt; 7);
    *y = ((cl &amp; 0x0c) &gt;&gt; 2) | ((cl &amp; 0x20) &gt;&gt; 3) | ((cl &amp; 0x80) &gt;&gt; 4) | ((cl &amp; 0x0200) &gt;&gt; 5) | ((cl &amp; 0x0800) &gt;&gt; 6) | ((cl &amp; 0x2000) &gt;&gt; 7) | ((cl &amp; 0x8000) &gt;&gt; 8);


which basically converts num to an x,y coordinate.  This is equivalent to getting the x,y position of num in the following array

$\left| \begin{array}{ccc}
0 &amp;1 &amp;4 &amp;5 &amp;16 &amp;17 &amp;20 &amp;21 &amp;...\\
2 &amp;3 &amp;6 &amp;7 &amp;18 &amp;19 &amp;22 &amp;23 &amp;...\\
8 &amp;9 &amp;12 &amp;13 &amp;24 &amp;25 &amp;28 &amp;29 &amp;...\\
10 &amp;11 &amp;14 &amp;15 &amp;26 &amp;27 &amp;30 &amp;31 &amp;...\\
32 &amp;33 &amp;36 &amp;37 &amp;48 &amp;49 &amp;52 &amp;53 &amp;...\\
34 &amp;35 &amp;38 &amp;39 &amp;50 &amp;51 &amp;54 &amp;55 &amp;...\\
40 &amp;41 &amp;44 &amp;45 &amp;56 &amp;57 &amp;60 &amp;61 &amp;...\\
42 &amp;43 &amp;46 &amp;47 &amp;58 &amp;59 &amp;62 &amp;63 &amp;...\\
\vdots &amp;\vdots &amp;\vdots &amp;\vdots &amp;\vdots &amp;\vdots &amp;\vdots &amp;\vdots &amp;\ddots &amp;
\end{array} \right|$

The array above follows a pattern where for all $k,n$, all numbers between $k4^n$ and $(k+1)4^n-1$ form a perfect square.

Can the code above be sped up without generating a ginormous list and storing all the values?  Or is there a completely different, faster method?
I think that the fastest approach with modern CPUs is

i = num &amp; 255
j = num &gt;&gt; 8
*x = x1[i] + x2[j]
*y = y1[i] + y2[j]


That is 4 arithmetic ops plus 4 loads