项目中,x坐标传的是负数 -1 ,再获取x坐标数据时返回了一个很大的数 4294967295 ,想在前端处理需要把无符号数转成有符号数,代码如下:
var x = 4294967295 << 0; // << 0 无符号数转换为有符号数
console.log(x); // -1
var signed = -10;
var unsigned = signed >>> 0; // >>> 0 转换为无符号数
console.log(unsigned); // 4294967286
signed = unsigned << 0; // << 0 转换为有符号数
console.log(signed); // -10