I have the following Java code:
long num = 3482085570325547757;
// Discard all but the highest priority 31 bits
int result = (int) (num >>> 33); // Returns 405368112
I am trying to do the equivalent in Javascript (using the https://github.com/oracle/graaljs engine), however, it is not giving me the same result as the Java code:
const num = 3482085570325547757;
// Discard all but the highest priority 31 bits
const result = num >>> 33; // Returns 1281508608
I thought it may have to do with the way GraalJS stores numbers internally as ints and doubles? I've tried explicitly casting to int as well using the below but it also gave me a different result to the Java code:
const Long = Java.type('java.lang.Long');
const String = Java.type('java.lang.String');
const BigInteger = Java.type('java.math.BigInteger');
const num = 3482085570325547757;
// Discard all but the highest priority 31 bits
const result = BigInteger.valueOf(num >>> 33).intValue(); // Returns 1281508608