-2

I want to calculate the value of -110 * -110 * 0x4c1906

When calculated in java I get the result 214876056.

But when tested with python I get 60344418200

Java

public class test{ 

    public static void main(String args[]) 
    { 
        int value = -110;
        int result = value * value * 0x4c1906;
        System.out.println(result);

    } 
}

Python

value = -110
result = value * value * 0x4c1906
print(result)

I want to know where the difference is.

quamrana
  • 33,740
  • 12
  • 54
  • 68

1 Answers1

7

In java, 4987142*110*110 is greater than the maximum value an integer can take on (2147483647). Python doesn't have the same limit.

If you cast to a long, you get the correct answer:

System.out.println((long)0x4c1906*110*110);

QWERTYL
  • 1,104
  • 5
  • 10