'Java and Javascript - different results using Unsigned right shift operator
I did a code migration from javascript to java, but the results for the following operation are different:
in javascript:-1316818646 >>> 0 = 2978148650
but in java: -1316818646 >>> 0 = -1316818646
Could someone help me, please? I didn't find the answer elsewhere
Solution 1:[1]
As @Pydawan said, 2978148650 is just the unsigned value of -1316818646 or 10110001100000101111000100101010. To get that in Java, call
Integer.toUnsignedLong(-1316818646)
Solution 2:[2]
In Java the operator returns you the same number as an int. In JavaScript the >>> operator always returns you an unsigned 32-bit integer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shmosel |
| Solution 2 | Pydawan |
