坐标转化和前端保持一致

back_recharge
mashiyu 2019-01-04 14:08:46 +08:00
parent 11cd52dbd8
commit eaea13a4b3
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package com.ljsd.jieling.util;
public class ToolsUtil {
public static int xy2Pos(int x, int y) {
return (x << 8) | y;
}
public static int[] pos2XY(int pos) {
int[] xy = new int[2];
xy[0] = (pos >> 8) & 0xff;
xy[1] = pos & 0xff;
return xy;
}
public static void main(String[] args) {
int xx = 12;
int yy = 5;
int pos = xy2Pos(xx,yy);
System.out.println("======> pos : "+pos);
int[] xy = pos2XY(pos);
System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
}
}