Page 36 - CTS - CSA TP - Volume 2
P. 36

COMPUTER SOFTWARE APPLICATION - CITS




           3  Bitwise Right Shift Operations:
              •  The program performs both right shift (>>) and unsigned right shift (>>>) operations on both positive and
                 negative numbers.
           4  Examples:
              •  System.out.println(20 >> 2);
              •  Right shift the binary representation of 20 by 2 positions using the >> operator.
              •  After right shifting by 2, 20 becomes 5 in decimal.

              •  Output: 5
              •  System.out.println(20 >>> 2);
              •  Unsigned right shift the binary representation of 20 by 2 positions using the >>> operator.
              •  After unsigned right shifting by 2, 20 becomes 5 in decimal.

              •  Output: 5
              •  System.out.println(-20 >> 2);
              •  Right shift the binary representation of -20 by 2 positions using the >> operator.
              •  For negative numbers, the vacant leftmost positions are filled with the sign bit (1), and -20 becomes -5 in
                 decimal.
              •  Output: -5
              •  System.out.println(-20 >>> 2);
              •  Unsigned right shift the binary representation of -20 by 2 positions using the >>> operator.
              •  The  unsigned  right  shift  fills  the  vacant  leftmost  positions  with  0,  and  -20  becomes  a  positive  integer
                 (1073741819 in decimal).
              •  Output: 1073741819
           Output:
















           TASK 9: Java AND Operator Example: Logical && and Bitwise &
           public class OperatorExample9{

           public static void main(String args[]){
           int a=10;
           int b=5;
           int c=20;

           System.out.println(a<b&&a<c);//false && true = false
           System.out.println(a<b&a<c);//false & true = false
           }}





                                                           21
 CITS : IT & ITES - Computer Software Application - Exercise 82  CITS : IT & ITES - Computer Software Application - Exercise 82
   31   32   33   34   35   36   37   38   39   40   41