How can I detect integer overflow on 32 bits int?
I know such topic was asked several times, but my question is about overflow on full 32 bits of int . For example: 11111111111111111111111111111111 + 00000000000000000000000000000001 = 00000000000000000000000000000000 //overflow! I found topic with similar question about this, however the algorithm is not perfect. 11111111111111111111111111111111 + 00000000000000000000000000000000 = 00000000000000000000000000000000 //overflow! Is there any simple and fast way to check this ? Since Java 8 there is a set of methods in the Math class: toIntExact (long), addExact (int,int), subtractExact (int,int)