Page 162 - Computer science 868 Class 12
P. 162

4.  Bitwise NOT (!) : This operator works like a logical NOT operator. It works on a single bit only. If the input is low, the
                 output is high else vice-versa. It results in a single bit only.

                                                    A                          !A
                                                     0                         1
                                                     1                         0

              6.5.5 Shift Operators
              These operators are used for shifting the bits to the value of the first operand towards right or left. They are used to
              perform bit manipulation on data.
              There are three different types of shift operators in Java. They are as follows:

                               Sign                Operator                          Meaning

                      Left Shift (Signed)             <<           It helps to move all bits by a given number of bits to
                                                                   the left.
                      Right Shift (Signed)            >>           It helps to move all bits by a given number of bits to
                                                                   the right.
                      Right Shift (Unsigned)         >>>           The  result  is  same as the signed  right shift,  but  the
                                                                   empty leftmost positions are filled with 0.

              Let us see some examples of shift operators:

              1.  Left Shift Operator
                  class left_shift
                  {
                      public static void main()
                      {
                          byte n = 100, b;
                          int i;
                          i = n << 3;
                          b = (byte)(n << 3);
                          System.out.println("Original value: " + n);
                          System.out.println("i : " + i + " and b : " +  b);
                      }
                  }
                The output of the preceding program is as follows:












              2.  Right Shift Operator
                  class right_shift
                  {
                      public static void main()
                      {


                160160  Touchpad Computer Science-XII
   157   158   159   160   161   162   163   164   165   166   167