BITWISE OPERATORS IN C

Maha



Bitwise Operators In C 

In C programming, the operators that operate on data at the bit level are known as bitwise operators. Programming at the bit level is also referred to as bitwise operations. It has two numbers, either 0 or 1.

  

Bitwise Operators Are:

&   AND bitwise
|     OR bitwise
^    XOR bitwise
~    NOT bitwise
<<  left shift
>>  right shift


Example For Bitwise AND Operator:

Program:


  #include<stdio.h>
  int main() {
    int a = 8, b = 4;
    printf("Bitwise AND: %d\n",a&b); 
    return 0;
  }


Output:


  Bitwise AND: 0


Example For Bitwise OR Operator:

Program:


  #include<stdio.h>
  int main() {
    int a = 8, b = 6;
    printf("Bitwise OR: %d\n",a|b); 
    return 0;
  }


Output:


  Bitwise OR: 14



Example For Bitwise XOR Operator:

Program:


  #include<stdio.h>
  int main() {    int a = 8, b = 6;
    printf("Bitwise XOR: %d\n",a^b); 
    return 0;
  }


Output:


  Bitwise XOR: 14


Example For Bitwise With Left Shift Operator:

Program:


  #include<stdio.h>
  int main() {
    int a = 8, b = 5, c = 6;
    printf("Bitwise left shift: %d\n",c<<6); 
    return 0;
  }



Output:


  Bitwise left shift: 384


Example For Bitwise With Right Shift Operator:

Program:


  #include<stdio.h>
  int main() {
    int a = 8, b = 5, c = 6;
    printf("Bitwise right shift: %d\n",c>>6); 
    return 0;
  }


Output:


  Bitwise right shift: 0




More topic in C

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send