You only have to follow these rules:
- always end bit wise ops with
>>> 0so the result gets interpreted as unsigned. - don’t use
>>. If the left-most bit is 1 it will try to preseve the sign and thus will introduce1‘s to the left. Always use>>>.
Examples:
C: (3774191835 >> 2) | 2147483648
js: (3774191835 >>> 2 | 2147483648) >>> 0
C: 1986735448 << 1
js: (1986735448 << 1) >>> 0
C: 3774191835 & 4294967295
js: (3774191835 & 4294967295) >>> 0
Only if the last op is >>>, >>> 0 is not necessary.