Python / Javascript - integer bit exception or problem

I speak both languages ​​... but I have problems with an integer bitwise exclusive or logical operator. In javascript it gives me one result, in python it gives me another.

Go ahead, open python and do (-5270299) ^ 2825379669

Now use javascript to do the same calculation and report the result or something else (example http://thorat.org/OS/js.php )

The results are different! I do not know why!

I SHOULD miss something.

+3
source share
3 answers

JavaScript 32-, Python long, 32 . Python 32 , 32 , :

>>> (-5270299 & 0xFFFFFFFF) ^ 2825379669
1472744368L
>>> (-5270299 ^ 2825379669) & 0xFFFFFFFF
1472744368L
+8

2825379669 32 .

JavaScript - 64- , 32- , , 64- float.

, Python long ( 32 ) .

, JavaScript, , , 64- JavaScript, . , , float int .

+2

No, it is not. Python simply preserves the sign because it can handle large integers.

js> ((-5270299) ^ 2825379669).toString(16)
57c84bb0

>>> hex((-5270299 ^ 2825379669))
'-0xa837b450'
>>> hex((-5270299 ^ 2825379669)+2**32)
'0x57c84bb0'
0
source

Source: https://habr.com/ru/post/1781530/


All Articles