int z = -1; int m = z>>1; System.out.println("the values is " +m);
Output is
the values is -1
but my doubt is how it happening internally, Can any explain? Step by step procedure.
int z = 2; int m = z>>1;
the z value in binary
00000000 00000000 00000000 00000010
,
After the value is shifted then the m value in binary will be as
00000000 00000000 00000000 00000001
, when I print m
value it will be as 1
, but my question is, what is happening if I use negative value for z variable and when I assign z value with -1 why output variable has -1 itself? ( Two complement will happen are not?)