Bitwise Operators

Bitwise Operators

  • & –> If both operands are true, then the result will be true.
  • Ι –> If at least one arg is true, then the result is true.
  • ∧ ( XOR ) –> If both args are different the result is true.
  • s.o.p ( true & false ) ; // false
  • s.o.p ( true / false ) ; // true
  • s.o.p ( 4 8 5 ) ; // 4
  • s.o.p ( 1/5 ) ; // 5
  • s.o.p ( 4 Λ 5 ) ; // 1

Bitwise Complement Operators ( ~ )

We can apply this operator only for integral datatype but not for boolean types.

  • s.o.p ( ~ true ) ; // compile time error
  • s.o.p ( ~ 4 ) ; // 5

Negative numbers are represented in 2’s complement form

MSB—-> represent sign bit

0 means   +ve

1 means   -ve

Boolean Complement Operator ( ! )

  • s.o.p ( ! true ) ; // false
  • s.o.p ( ! false ) ; // true
  • s.o.p ( ! 4 ) ; // compile time error
Note:-
&, !, ^ ==> Applicable for boolean and integral types.
~ ==> Applicable only for integral types.
! ==> Applicable only for boolean types.

Leave a Reply