Page 342 - Computer_Science_F5
P. 342

Table 5.9: Bitwise operators
               Operator Type     Symbol     Description                      Syntax
                                                                             Example

               left              <<         This  operation  moves  the  first  A<<n               Chapter Five: Object oriented programming with Java
          FOR ONLINE READING ONLY
               shift                        operand a certain number of bits
                                            to the left, as determined by the
                                            second operand. Zeros are filled
                                            in  from the  right  as the shift
                                            occurs.
               right             >>         This  operation  moves  the  first  A>>n
               shift                        operand  a  specified  number  of
                                            bits to the  right,  as determined
                                            by the second operand. Any bits
                                            that are shifted out of the right
                                            end are discarded.

               Unsigned right    >>>        The value of the left  operand  A>>>n
                shift (Zero fill            is shifted to the right by the
                right shift)                number  of  bits  specified  by  the
                                            right operand. Any empty spaces
                                            created  by  the  shift  are  filled
                                            with zeros
               Bitwise AND       &          This operation copies a bit to  A&B
                                            the result if it is present in both
                                            operands.  The result will be 1
                                            only if both bits are 1

               Bitwise OR        |          This operation transfers a bit to  A|B
                                            the result if it is present in either
                                            operand. The result will be 1 if
                                            either of the bits is 1
               Bitwise XOR       ^          In the result, each bit is set to 1  A^B
                                            if the corresponding bits in both
                                            operands are not the same

               Bitwise           ~          This operation                   ~A
               complement                   it changes zeros to ones and ones
                                            to zeros


                                                    333
               Student’s Book  Form Five



     Computer Science Form 5.indd   333                                                     23/07/2024   12:34
   337   338   339   340   341   342   343   344   345   346   347