Skip to main content

// Birwise Operator

 // Birwise Operator


  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a = 50;  //110010 in binary.
  6. int b = 30; //11110 in binary.
  7. int c = 0; //int use for integer value.
  8. int d = 0;
  9. int e = 0;
  10. int f = 0;
  11. int g = 0;
  12. int h = 0;

  13. //Bitwise AND 
  14. c = a & b; // 110010 & 11110 = 10010 i.e means is '18'.
  15. cout<<"the value of AND is:"<<c<<endl;

  16. //Bitwise OR
  17. d = a | b; // 110010 | 11110 = 111110 i.e means is '62'.
  18. cout<<"the value of OR is:"<<d<<endl;

  19. //Bitwise Exclusive XOR
  20. e = a ^ b; // 110010 ^ 11110 = 101100 i.e means is '44'.
  21. cout<<"the value of Exclusive OR is:"<<e<<endl;

  22. //Bitwise Complement of a
  23. f = ~a; //-(50+1)= i.e means is '-51'.
  24. cout<<"the value of Complement is:"<<f<<endl;

  25. //Bitwise Shift Left
  26. g = a << 2; //50=110010 << 2 :- 11001000 i.e means is '200'. //Shift with 2 zero to left side.
  27. cout<<"the value of Shift Left is:"<<g<<endl;

  28. //Bitwise Shift Right
  29. h = a >> 2; // 50=110010 >> 2 :-  001100 i.e means os '12'. //Shift with 2 zero to right side.
  30. cout<<"the value of Right Shift is:"<<h<<endl;

  31. return 0;

  32. }

//Here You Can Execute The Program

//Execute


//Output

/*

  the value of AND is:18

  the value of OR is:62

  the value of Exclusive OR is:44

  the value of Complement is:-51

  the value of Shift Left is:200

  the value of Right Shift is:12

 

 */







                    //ThE ProFessoR