public static int hilbertXYToIndex(int level, int x, int y) {
    x = x << (16 - level);
    y = y << (16 - level);

    int hA, hB, hC, hD;

    int a1 = x ^ y;
    int b1 = 0xFFFF ^ a1;
    int c1 = 0xFFFF ^ (x | y);
    int d1 = x & (y ^ 0xFFFF);

    hA = a1 | (b1 >>> 1);
    hB = (a1 >>> 1) ^ a1;

    hC = ((c1 >>> 1) ^ (b1 & (d1 >>> 1))) ^ c1;
    hD = ((a1 & (c1 >>> 1)) ^ (d1 >>> 1)) ^ d1;

    int a2 = hA;
    int b2 = hB;
    int c2 = hC;
    int d2 = hD;

    hA = ((a2 & (a2 >>> 2)) ^ (b2 & (b2 >>> 2)));
    hB = ((a2 & (b2 >>> 2)) ^ (b2 & ((a2 ^ b2) >>> 2)));

    hC ^= ((a2 & (c2 >>> 2)) ^ (b2 & (d2 >>> 2)));
    hD ^= ((b2 & (c2 >>> 2)) ^ ((a2 ^ b2) & (d2 >>> 2)));

    int a3 = hA;
    int b3 = hB;
    int c3 = hC;
    int d3 = hD;

    hA = ((a3 & (a3 >>> 4)) ^ (b3 & (b3 >>> 4)));
    hB = ((a3 & (b3 >>> 4)) ^ (b3 & ((a3 ^ b3) >>> 4)));

    hC ^= ((a3 & (c3 >>> 4)) ^ (b3 & (d3 >>> 4)));
    hD ^= ((b3 & (c3 >>> 4)) ^ ((a3 ^ b3) & (d3 >>> 4)));

    int a4 = hA;
    int b4 = hB;
    int c4 = hC;
    int d4 = hD;

    hC ^= ((a4 & (c4 >>> 8)) ^ (b4 & (d4 >>> 8)));
    hD ^= ((b4 & (c4 >>> 8)) ^ ((a4 ^ b4) & (d4 >>> 8)));

    int a = hC ^ (hC >>> 1);
    int b = hD ^ (hD >>> 1);

    int i0 = x ^ y;
    int i1 = b | (0xFFFF ^ (i0 | a));

    return ((interleave(i1) << 1) | interleave(i0)) >>> (32 - 2 * level);
  }
Returns the hilbert index at {@code level} for an x/y coordinate.
planetiler-core/src/main/java/com/onthegomap/planetiler/util/Hilbert.java