Signed to Unsigned and Vice Versa (arithmetical)

后端 未结 3 840
逝去的感伤
逝去的感伤 2021-01-16 13:43

How to convert a number from unsigned to signed?

signed: -32768 to 32767 unsigned: 0 to 65535

I am solving the problem in JavaScript. The situation is that I

3条回答
  •  星月不相逢
    2021-01-16 14:17

    Just test if the number is over halfway, then subtract the modulus.

    if(x > 32767) {x = x - 65536;}
    

提交回复
热议问题