Javascript & PHP Xor equivalent

前端 未结 1 1153
误落风尘
误落风尘 2020-12-06 15:07

I have a javascript code:

var c = 267414715;
var d = c ^ (\"0x81BE16CD\");

Result is -1907459466

http://jsfiddle.net/4

相关标签:
1条回答
  • 2020-12-06 15:14

    2387507830 == -1907459466 when using unsigned integers (look at the bit values of the least significant bits)

    2387507830 = 0000 0000 0000 0000 0000 0000 0000 0000 1000 1110 0100 1110 0111 1010 0111 0110 -1907459466= 1111 1111 1111 1111 1111 1111 1111 1111 1000 1110 0100 1110 0111 1010 0111 0110

    your problem is a 32 bit roll over. To compensate you can simply & 0xffffffff which will 0 out the most significant 32 bits, and make both answers the same.

    0 讨论(0)
提交回复
热议问题