public static long encode(int x, int y) {
        long xl = x;
        long yl = y;

        long rx = ((xl & 0x00000000ffff0000L) << 16) | (xl & 0x000000000000ffffL);
        long ry = ((yl & 0x00000000ffff0000L) << 16) | (yl & 0x000000000000ffffL);

        rx = ((rx & 0xff00ff00ff00ff00L) << 8) | (rx & 0x00ff00ff00ff00ffL);
        ry = ((ry & 0xff00ff00ff00ff00L) << 8) | (ry & 0x00ff00ff00ff00ffL);

        rx = ((rx & 0xf0f0f0f0f0f0f0f0L) << 4) | (rx & 0x0f0f0f0f0f0f0f0fL);
        ry = ((ry & 0xf0f0f0f0f0f0f0f0L) << 4) | (ry & 0x0f0f0f0f0f0f0f0fL);

        rx = ((rx & 0xccccccccccccccccL) << 2) | (rx & 0x3333333333333333L);
        ry = ((ry & 0xccccccccccccccccL) << 2) | (ry & 0x3333333333333333L);

        rx = ((rx & 0xaaaaaaaaaaaaaaaaL) << 1) | (rx & 0x5555555555555555L);
        ry = ((ry & 0xaaaaaaaaaaaaaaaaL) << 1) | (ry & 0x5555555555555555L);

        return (rx | (ry << 1));
     }
Encode two 32 bit integers by bit-interleaving them into one 64 bit
integer value. The x-direction owns the least significant bit (bit
0). Both x and y can have negative values.

<p>
This is a time-efficient implementation. In the first step, the input
value is split in two blocks, one containing the most significant bits, and
the other containing the least significant bits. The most significant block
is then shifted left for as many bits it contains. For each following step
every block from the previous step is split in the same manner, with a
least and most significant block, and the most significant blocks are shifted
left for as many bits they contain (half the number from the previous step).
This continues until each block has only one bit.

<p>
This algorithm works by placing the LSB of all blocks in the correct position
after the bit-shifting is done in each step. This algorithm is quite similar
to computing the Hamming Weight (or population count) of a bit
string, see http://en.wikipedia.org/wiki/Hamming_weight.

<p>
Efficiency considerations: The encoding operations in this method
should require 42 cpu operations, of which many can be executed
in parallell. Practical experiments show that one call takes ~15 ns
on a 64-bit Intel Xeon processor @2.33GHz, or 35 cycles. This gives
an efficiency gain of just ~17% due to the CPUs ability to process
parallell instructions, compared to ~50% for the slow method.
But still it is 5 times faster.

@param x  x value
@param y  y value
@return  The bit-interleaved long containing x and y.
vespajlib/src/main/java/com/yahoo/geo/ZCurve.java