+ 1

When we assign byte value as 130 in java then it gives -126 why this result is come? I don't understand..

24th Aug 2019, 3:52 PM
Akshay Harshora
Akshay Harshora - avatar
3 odpowiedzi
+ 6
Because of the limits of the type byte: between -128 and 127, when incrementing it above the upper limit it starts again from the lower limit, so we need to increase it 3 times above the upper limit (130 -127 = 3). First step => -128, second => -127 and third => -126 is the final result.
24th Aug 2019, 3:58 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 5
Just adding to WhiteCat's explanation, this is called an overflow. https://en.m.wikipedia.org/wiki/Integer_overflow
24th Aug 2019, 4:04 PM
Hatsy Rei
Hatsy Rei - avatar