The Java language provides three operator for performing bitwise shifting on 32 and 64 bit integer values. These are all binary operators with the first operand being the value to be shifted, and the second operand saying how far to shift.
Notes:
The following table will help you see the effects of the three shift operators. (The numbers have been expressed in binary notation to aid vizualization.)
Operand1 | Operand2 | << | >> | >>> |
---|---|---|---|---|
0b0000000000001011 | 0 | 0b0000000000001011 | 0b0000000000001011 | 0b0000000000001011 |
0b0000000000001011 | 1 | 0b0000000000010110 | 0b0000000000000101 | 0b0000000000000101 |
0b0000000000001011 | 2 | 0b0000000000101100 | 0b0000000000000010 | 0b0000000000000010 |
0b0000000000001011 | 28 | 0b1011000000000000 | 0b0000000000000000 | 0b0000000000000000 |
0b0000000000001011 | 31 | 0b1000000000000000 | 0b0000000000000000 | 0b0000000000000000 |
.... | .... | .... | .... | .... |
0b1000000000001011 | 0 | 0b1000000000001011 | 0b1000000000001011 | 0b1000000000001011 |
0b1000000000001011 | 1 | 0b0000000000010110 | 0b1100000000000101 | 0b0100000000000101 |
0b1000000000001011 | 2 | 0b0000000000101100 | 0b1110000000000010 | 0b0010000000000010 |
0b1000000000001011 | 31 | 0b1000000000000000 | 0b1111111111111111 | 0b0000000000000001 |
There examples of the user of shift operators in Bit manipulation
This operator checks whether the object is of a particular class/interface type. instanceof operator is written as:
( Object reference variable ) instanceof (class/interface type)
Example:
public class Test { public static void main(String args[]){ String name = "Buyya"; // following will return true since name is type of String boolean result = name instanceof String; System.out.println( result ); } }
This would produce the following result:
true
This operator will still return true if the object being compared is the assignment compatible with the type on the right.
Example:
class Vehicle {} public class Car extends Vehicle { public static void main(String args[]){ Vehicle a = new Car(); boolean result = a instanceof Car; System.out.println( result ); } }
This would produce the following result:
true
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions