Can someone explain to me why .net is calculating these differently to Java
The equation
(-1646490243 << 4) + 3333 ^ -1646490243 + -957401312 ^ (-1646490243 >> 5) + 4
Java calculates it as
1173210151
.Net calculates as
-574040108
My issue is that I need .Net to calculate the same as Java as i'm porting across a decryption function and if it calculates differently then the decryption isn't going to be right.
Any help would be appreciated.
--Update--
Thanks guys, Xor was what I should of been using. Plus need to workaround Java not throwing an exception when an Integer number is too big.
Xor gives a result of -3121757145
(-1646490243 << 4) + 3333 Xor -1646490243 + -957401312 Xor (-1646490243 >> 5) + 4
Combine this with the answer from this link I found - Java sum 2 negative numbers. Gives the same result as Java
-3121757145 + 2 ^ 32 = 1173210151
I checked the operator precedence table for Java and Visual Basic, they're the same regarding the operators in the expression. So it's not a problem with precedence.
Be aware though, in Visual Basic ^
is the operator for exponentiation, whereas Xor
is the operator for exclusive or. That's different from Java, which uses the ^
operator as exclusive or and doesn't have an operator for exponentiation. All the other operators in the expression are the same in both languages
I can't tell from the code if the snippet is the one in Java or the one in Visual Basic - I'm guessing is in Java. If that's the case, it's quite possible that you've confused the exclusive or; try replacing ^
with Xor
in the Visual Basic code and see if that fixes the problem:
(-1646490243 << 4) + 3333 Xor -1646490243 + -957401312 Xor (-1646490243 >> 5) + 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With