difference between JavaScript bit-wise operator code and Python bit-wise operator code

大兔子大兔子 提交于 2019-12-06 03:54:02

If you want the java-script equivalent value then what you can do is :

import ctypes

print(ctypes.c_int(424970184 << 10 ^ 0).value)

Output:

1377771520
Jean-François Fabre

As stated in this SO answer, in javascript the bitwise operators and shift operators operate on 32-bit ints, and your second example overflows the 32 bit capacity, so the python equivalent would be:

(424970184 << 10) & 0x7FFFFFFF

(you get a "modulo"/"masked" value with the signed 32 bit integer mask, not the actual value)

In Python there's no limit in capacity for integers, so you get the actual value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!