js realizes unsigned number and signed number conversion

 In the project, the x-coordinate is passed a negative number -1, and then when the x-coordinate data is obtained, a large number 4294967295 is returned. If you want to process the front-end, you need to convert an unsigned number to a signed number. The code is as follows:

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

 

Guess you like

Origin blog.csdn.net/qq_40015157/article/details/113867957