Take the 2-minute tour ×

In normal maths terms, -1756046391 * -1291488517 will equal 2267913749295792147.

When i enter the exact same equation in java, i get the answer: -1756046391 * -1291488517 = 19.

Can anyone shed any light on this?

share|improve this question
Overflow. Check out Integer.MAX_VALUE. –  duffymo May 9 '12 at 11:31
Try this: -1756046391L * -1291488517. You are using unchecked operations on primitive ints. –  Marko Topolnik May 9 '12 at 11:32

4 Answers 4

up vote 6 down vote accepted


Check out Integer.MAX_VALUE. An Integer in Java is a 32 bit 2s complement value. You can't exceed the MAX_VALUE.

share|improve this answer
Thanks, will accept answer when i can! –  Adam May 9 '12 at 11:38
+1 I suspect (int) 2267913749295792147L is 19. –  Peter Lawrey May 9 '12 at 11:51

When dealing with very large numbers, you need to make sure the data type you used is big enough to store that number. In java you have these primitive number types:

type:                      min:                      max:
byte                       -128                       127
short                    -32768                     32767
int              -2,147,483,648             2,147,483,647
long -9,223,372,036,854,775,808 9,223,372,036,854,775,807

So as you can see, your number would just about fit into a long. But you're bound to go over that, so you should probably use the BigInt class instead:


share|improve this answer

Either use longs as others said, or if that is not enough for your application, consider using BigInteger.

share|improve this answer

Post the exact code you used to reproduce this.

You are most likely using ints. Use longs, because 2267913749295792147 is too big to fit in an int.

share|improve this answer
He should use a BigInt object, since his number*5 would overflow a long. –  Ozzy May 9 '12 at 11:39

Your Answer


