Bitwise Operations

1. AND ( &)
2. OR ( | )
3. COMPLEMENT ( ~ )
4.  X-OR (  ^ )
5. LEFT SHIFT ( <<  )
6. RIGHT SHIFT ( >> )

Bits are 0 or 1.

1. AND ( & )

if and only two bits are 1's then result is 1 else 0
  0 & 0 = 0
  0 & 1 = 0
  1 & 0 = 0
  1 & 1 = 1

Ex: a = 0010 , b = 1010
0010
1010  
------
0010   a & b 
------
   
1. OR ( | )

if and only two bits are 0's then result is 0 else 1
  0 | 0 = 0
  0 | 1 = 1
  1 | 0 = 1
  1 | 1 = 1

Ex: a = 0010 , b = 1010
0010
1010  
------
1010   a | b 
------

3. COMPLEMENT ( ~ )

It flips the bits. 

  ~ 0  = 1
  ~ 1  = 0

Ex: a = 0010 
0010
------
1101  ~a  
------

4. X-OR ( ^ )

if and only two bits are same 1's  or 0's then result is 0 else 1. This is used for flip the bits i.e. value ^ 1.
  0 ^ 0 = 0
  0 ^ 1 = 1
  1 ^ 0 = 1
  1 ^ 1 = 0

Ex: a = 0010 , b = 1010
0010
1010  
------
1000   a ^ b 
------

5. LEFT SHIFT ( <<  )

shifts the number bit position to right. acts as multiplication of 2
  
  1010 << 1 = 10100

Ex: a = 0010 ,

a << 2 = 1000

5. LEFT SHIFT ( <<  )

shifts the number bit position to left. acts as division of 2
  
  1010 >> 1 = 0101

Ex: a = 1000 ,

a  >> 2 = 0010