Posts

Showing posts with the label Logic

Shift operator in java

Shift operator in java Java supports two types of shift operator (Logical Shift and Arithmetic shift). Logical Shift : In logical shift simply all the bits except the extreme left or right bit is moved by one place. and The extra bit from the other end is replaced with zero. For Example for The number 4 (binary = 0000 0100) Logical Shift ( >>>, << )                              original number        0 000 0100              (Decimal 4)                              after left shift           000 0100 0              (Decimal 8)                              original number           0000 010 0             (Decimal 4)                              after left shift              0 000 0010             (Decimal 2) Java logical left shift operator is represented by (<<) and right shift operator is represented by (>>>) Example, 11000000 >>> 2 = 00 11000000 01000000 << 2 = 00000000 Arithmetic shift :  Signed Left Shift