// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Convert {
    public static Pos ExtToInt(Pos p) {
        return new Pos(p.getX() * 32 + p.getY() * 32, p.getY() * 16 - p.getX() * 16);
    }
    public static Pos IntToExt(Pos p) {
        return new Pos((p.getX() - 2 * p.getY()) / 64, (p.getX() + 2 * p.getY()) / 64);
    }
    public static void main(String[] args) {
        Pos p1 = new Pos(39, 117);
        System.out.println(p1);
        Pos p2 = ExtToInt(p1);
        System.out.println(p2);
        Pos p3 = IntToExt(p2);
        System.out.println(p3);
    }
}

class Pos {
    private int x;
    private int y;
    public Pos() {
        this(0, 0);
    }
    public Pos(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
    @Override
    public String toString() {
        return "(" + x + "," + y + ")";
    }
    @Override
    public boolean equals(Object obj) {
        return obj != null
                && obj instanceof Pos
                && x == ((Pos)obj).x
                && y == ((Pos)obj).y;
    }
    @Override
    public int hashCode() {
        return x + y;
    }
}
