using bitwise OR in javascript to convert to integer

被刻印的时光 ゝ 提交于 2019-12-01 12:28:14

Yes, it is standard behavior. Bitwise operators only operate on integers, so they convert whatever number they're give to signed 32 bit integer.

This means that the max range is that of signed 32 bit integer minus 1, which is 2147483647.

(Math.pow(2, 32) / 2 - 1)|0; // 2147483647

(Math.pow(2, 32) / 2)|0; // -2147483648 (wrong result)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!