Mask-group

One’s Complement Operator



  • On taking one’s complement of a number, all 1’s present in the number are changed to 0’s and all 0’s are changed to 1’s.

  • One’s complement operator is represented by the symbol ~.

Right Shift Operator:

  • The right shift operator is represented by >>. It needs two operands. It shifts each bit in its left operand to the right. The number of places the bits are shifted depends on the number following the operator.

  • Thus, ch >> 4 would shift all bits in ch four places to the right. Similarly, ch >> 3 would shift all bits three places to the right. 

  • Note that as the bits are shifted to the right, blanks are created on the left. These blanks are always filled with zeros.

Left Shift Operator:

  • This is similar to the right shift operator, the only difference being that the bits are shifted to the left, and for each bit shifted, a 0 is added to the right of the number. 

  • Thus, ch << 4 would shift all bits in ch four places to the left. Similarly, ch << 3 would shift all bits three places to the left. 

Bitwise AND Operator:

  • This operator is represented as &.The & operator operates on two operands. While operating upon these two operands they are compared on a bit-by-bit basis. Hence both the operands must be of the same type (either char or int).

Bitwise OR Operator:

  • Another important bitwise operator is the OR operator which is represented as |.