Page 55 - Cs_withBlue_J_C11_Flipbook
P. 55

a. Bitwise complement operator is a unary operator (works on a single operand) which inverts  0 to 1 and 1 to 0. It can
                   be represented in the following table:

                                                              Bit         ˜
                                                              0           1
                                                              1           0
                 b. Bitwise AND is a binary operator (works on two operands) which results in 1 if both bits are 1. It produces 0 in other
                   cases. The following table represents its operation.

                                                       Bit1        Bit2         &
                                                        0           0           0
                                                        0           1           0
                                                        1           0           0
                                                        1           1           1

                 c. Bitwise OR is a binary operator which gives 1 if any of the two bits or both the bits are 1. Only if both bits are 0, it
                   results in 0 as shown below in the table.

                                                       Bit1        Bit2         |
                                                        0           0           0
                                                        0           1           1
                                                        1           0           1
                                                        1           1           1
                 d. Bitwise XOR is a binary operator which gives 1 for odd combinations of 1. For all 0’s or even combinations of 1, it
                   results in 0 as demonstrated in the following table.

                                                       Bit1        Bit2         ∧
                                                        0           0           0

                                                        0           1           1
                                                        1           0           1
                                                        1           1           0

                 Some problems on bitwise operators are given below.
                 Example 1:  Find the result of the operation 26 | 12.               0   0   0   1   1   0   1   0
                                                                                 |   0   0   0   0   1   1   0   0
                 Binary value of 26 represented in 8-bits is 00011010
                                                                                     0   0   0   1   1   1   1   0
                 Binary representation of 12 in 8-bits form is 00001100
                 Result of bitwise | is 00011110
                                                              1
                                                       2
                                        4
                                                3
                 Decimal equivalent is 1 × 2  + 1 × 2  + 1 × 2  + 1 × 2  = 30
                                                                                      0   0   0   1   1  0   1   0
                 Example 2: Find the result of the operation 26 & 12.
                                                                                  &   0   0   0   0   1  1   0   0
                 Binary value of 26 represented in 8 bits is 00011010
                                                                                      0   0   0   0  1   0   0   0
                 Binary representation of 12 in 8 bits form is 00001100
                 Result of bitwise & is 00001000
                                        3
                 Decimal equivalent is 1 × 2  = 8




                                                                                                                        53
                                                                                                            Encoding    53
   50   51   52   53   54   55   56   57   58   59   60