Multiplication of two ints overflowing to result in a negative number

Java (like most computer architectures these days) uses something called two’s complement arithmetic, which uses the most significant bit of an integer to signify that a number is negative. If you multiply two big numbers, you end up with a number that’s so big it sets that highest bit, and the result ends up negative.

Leave a Comment