Beruflich Dokumente
Kultur Dokumente
So the result of doing a zero fill right shift by 2 on 13 is 3. The next example explains
the effect of applying the operator >>> on a negative number.
int b = -11; //11111111 11111111 11111111 1111 0101
b = b >>> 2; // b now becomes 00111111 11111111 11111111 1111 1101
So the result of applying zero fill right shift operator with operand two on -11 is
1073741821.
Signed right shift operator (>>) fills the left most bit by the sign bit. The result of
applying the signed shift bit has the same sign as the left operand. For positive
numbers the signed right shift operator and the zero fill right shift operator both give
the same results. For negative numbers, their results are different. The example below
illustrates the signed right shift.
int b = -11; // 11111111 11111111 11111111 1111 0101
b = b >> 2; // 11111111 11111111 11111111 1111 1101 (2's complement
of -3)
// Here the sign bit 1 gets filled in the two most significant bits.