int xy2d(int n, int x, int y) {
        int[] xy = new int[2];
        int rx, ry, d = 0;
        // loop over bits not value
        for (int s = n >> 1; s != 0; s >>= 1) {
            rx = (x & s) != 0 ? 1 : 0; // todo better, perhaps 0*x or / s aka >>
            ry = (y & s) != 0 ? 1 : 0;
            d += s * s * ((3 * rx) ^ ry);
            xy[0] = x;
            xy[1] = y;
            rot(s, xy, rx, ry);
        }
        return d;
    }
int xy2d ( int n , int x , int y ) { int [ ] xy = new int [ 2 ] ; int rx , ry , d = 0 ; for ( int s = n > > 1 ; s != 0 ; s >>= 1 ) { rx = ( x & s ) != 0 ? 1 : 0 ; ry = ( y & s ) != 0 ? 1 : 0 ; d += s * s * ( ( 3 * rx ) ^ ry ) ; xy [ 0 ] = x ; xy [ 1 ] = y ; rot ( s , xy , rx , ry ) ; } return d ; }
convert (x,y) to d