Unsigned Right Shift Operator in JavaShift operator is a special type of operator used for bit manipulation on data. The shift operators are used to shift the bits of its first operand left to right or right to left. There are three types of shiftoperators available in Java, i.e., rightshift operator, unsigned right shift operator and leftshift operator. Java doesn't support the unsigned leftshift operator.
Rightshift operatorThe Rightshift operator is a special type of operator which is used to move the bits of the shiftexpression to the right. The rightshift operator shifts the bits pattern to the right according to the number of positions specified the additiveexpression. Let's take an example of positive and integer numbers to understand how the rightshift operator work. Suppose, we have two numbers, i.e., x=40, and y=40 and the binary representation of these numbers are as follows: x => 40 => 0000 0000 0000 0000 0000 0000 0010 1000 Negative number is the 2's compliment of its positive number. So, Y => 40 => 1111 1111 1111 1111 1111 1111 1101 1000 Thus x >> 2 = 0000 0000 0000 0000 0000 0000 0000 1010 AND y >> 2 = 1111 1111 1111 1111 1111 1111 1111 0110 Leftshift operatorThe Leftshift operator is another type of operator which is used to move the bits of the shiftexpression to the left. The leftshift operator shifts the bits pattern to the left according to the number of positions specified the additiveexpression. Let's understand some example of the leftshift operator to understand how it actually works. x => 40 => 0000 0000 0000 0000 0000 0000 0010 1000 A negative number is the 2's complement of its positive number. So, Y => 40 => 1111 1111 1111 1111 1111 1111 1101 1000 Thus x >> 2 = 0000 0000 0000 0000 0000 0000 1010 0000 AND y >> 2 = 1111 1111 1111 1111 1111 1111 0110 1111 Unsigned rightshift operatorThe unsigned rightshift operator is a special type of rightshift operator that doesn't use the sign bit for filling the trailing position. The unsigned rightshift operator always fills the trialing position by 0. Let's take the same example of the rightshift operator to understand the concept of the leftshift operator. x => 40 => 0000 0000 0000 0000 0000 0000 0010 1000 A negative number is the 2's complement of its positive number. So, Y => 40 => 1111 1111 1111 1111 1111 1111 1101 1000 Thus x >>> 2 = 0000 0000 0000 0000 0000 0000 0000 1010 AND y >>> 2 = 0011 1111 1111 1111 1111 1111 1111 0110 ShiftOperatorExample.java Output
Next TopicInfix to Postfix Java
