How does java handle integer overflow and overflow?

I know this is an old question asked many times. but I cannot find a satisfactory answer for this, so I ask again. can someone explain what exactly happens in case of overflow of the whole and the lower stream? I heard about some lower order bytes that handle this, can anyone explain what this is?

thank!

+3
source share
4 answers

You could imagine that when you only have 2 places that you count (so adding 1 each time)

 00
 01
 10
 11 
100

"00". , "". 00. , , , , , . ( 11 00)

Mark peters : , , , . , "" .

+7

Java ( , ).

:

System.out.println(Integer.MAX_VALUE + 1 == Integer.MIN_VALUE);
System.out.println(Integer.MIN_VALUE - 1 == Integer.MAX_VALUE);

true.

+7

, , 2- , , ( ) , .

, , , , Integer.MIN_VALUE - 1 Integer.MAX_VALUE.

" " , . , Java- , , int, ints, , , , .

+2

Another way to think about how java handles overflow / overclocking is to use an anology clock image. You can move it forward an hour at a time, but in the end the clock will start again. You can wind the clock back, but as soon as you go beyond the start, you are at the end again.

0
source

All Articles