www.eshikshak.co.in
● An operator used for manipulation of data
   at bit level
 ● It is used for testing bits, shifting them
   right or left
 ● It works on integer and character data
   type
 ● It is not applied to float or double



www.eshikshak.co.in
Operator Meaning
~       One’s compliment
>>      Shift right
<<      Shift left
&       Bitwise AND
|       Bitwise OR
^       Bitwise exclusive OR




            www.eshikshak.co.in
● All the 1’s present in the number are changed to
   0’s and all 0’s are changed to 1’s

 ● Example
   1’s complement of 1101 = 0010
   1’s complement of 1010 = 0101




www.eshikshak.co.in
main()
{
int j,k;
j=12;
k=~j;
printf(“One’s complement of %d is”,j);
showbits(k);
}

Example
One’s complement of 12 is 0011




www.eshikshak.co.in
● It is represent by >>
 ● It shifts each bit in operand to the right
 ● Example
   ch >> 1
    This will shift all bits in ch one place to the right
ch >> 5
This will shift all bits in ch five places to the right



www.eshikshak.co.in
main()
{
int j,k,i;
i=12;
for(j=0;j<4;j++)
{
k = i >> j;
printf(“%d right shift %d gives”,i,j);
showbits(k);
}
}
Output
12 right shift 0 gives 1100
12 right shift 1 gives 0110
12 right shift 2 gives 0011
12 right shift 3 gives 0001




www.eshikshak.co.in
● It is represent by <<
 ● It shifts each bit in operand to the left
 ● Example
   ch << 1
    This will shift all bits in ch one place to the left
ch << 5
This will shift all bits in ch five places to the left



www.eshikshak.co.in
main()
{
int j,k,i;
i= 3;
for(j=0;j<4;j++)
{
k = i << j;
printf(“%d right shift %d gives”,i,j);
showbits(k);
}
}
Output
12 right shift 0 gives 0011
12 right shift 1 gives 0001
12 right shift 2 gives 0000
12 right shift 3 gives 0000




www.eshikshak.co.in
● & operator operates on two operands
● This operator will compared two operands on
  bit-by-bit basis
● Both the operands must be of same type
  (either char or int)
● & and && are different operator, && is logical AND operator whereas & is
  Bitwise AND operator


                 1st Bit        2nd Bit          1st & 2nd Bit
                 0              0                0
                 0              1                0
                 1              0                0
                 1              1                1


                           www.eshikshak.co.in
● The uses of bitwise AND operator

    a) It is used whether a particular bit in a number is ON
    or OFF
b) It is used to turn OFF a particular bit in a number




                    www.eshikshak.co.in
www.eshikshak.co.in

Lecture 11 bitwise_operator

  • 1.
  • 2.
    ● An operatorused for manipulation of data at bit level ● It is used for testing bits, shifting them right or left ● It works on integer and character data type ● It is not applied to float or double www.eshikshak.co.in
  • 3.
    Operator Meaning ~ One’s compliment >> Shift right << Shift left & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR www.eshikshak.co.in
  • 4.
    ● All the1’s present in the number are changed to 0’s and all 0’s are changed to 1’s ● Example 1’s complement of 1101 = 0010 1’s complement of 1010 = 0101 www.eshikshak.co.in
  • 5.
    main() { int j,k; j=12; k=~j; printf(“One’s complementof %d is”,j); showbits(k); } Example One’s complement of 12 is 0011 www.eshikshak.co.in
  • 6.
    ● It isrepresent by >> ● It shifts each bit in operand to the right ● Example ch >> 1 This will shift all bits in ch one place to the right ch >> 5 This will shift all bits in ch five places to the right www.eshikshak.co.in
  • 7.
    main() { int j,k,i; i=12; for(j=0;j<4;j++) { k =i >> j; printf(“%d right shift %d gives”,i,j); showbits(k); } } Output 12 right shift 0 gives 1100 12 right shift 1 gives 0110 12 right shift 2 gives 0011 12 right shift 3 gives 0001 www.eshikshak.co.in
  • 8.
    ● It isrepresent by << ● It shifts each bit in operand to the left ● Example ch << 1 This will shift all bits in ch one place to the left ch << 5 This will shift all bits in ch five places to the left www.eshikshak.co.in
  • 9.
    main() { int j,k,i; i= 3; for(j=0;j<4;j++) { k= i << j; printf(“%d right shift %d gives”,i,j); showbits(k); } } Output 12 right shift 0 gives 0011 12 right shift 1 gives 0001 12 right shift 2 gives 0000 12 right shift 3 gives 0000 www.eshikshak.co.in
  • 10.
    ● & operatoroperates on two operands ● This operator will compared two operands on bit-by-bit basis ● Both the operands must be of same type (either char or int) ● & and && are different operator, && is logical AND operator whereas & is Bitwise AND operator 1st Bit 2nd Bit 1st & 2nd Bit 0 0 0 0 1 0 1 0 0 1 1 1 www.eshikshak.co.in
  • 11.
    ● The usesof bitwise AND operator a) It is used whether a particular bit in a number is ON or OFF b) It is used to turn OFF a particular bit in a number www.eshikshak.co.in
  • 12.