I am trying to right shift an integer by 32 but the result is the same number.
(e.g. 5 >> 32
is 5.)
If I try to do same operation on Byte and Short it works. For example, "(byte)5 >> 8" is 0.
What is wrong with Integer?
I am trying to right shift an integer by 32 but the result is the same number.
(e.g. 5 >> 32
is 5.)
If I try to do same operation on Byte and Short it works. For example, "(byte)5 >> 8" is 0.
What is wrong with Integer?
A Shifting conversion returns result as an
int
orlong
. So, even if you shift abyte
, you will get anint
back.Java code :
Byte code :
JLS 15.19. Shift Operators
so shifting
32
is not effective.