Skip to main content

//Birwise Operator

Birwise Operator


  1.  <?php 
  2. $a = 50; //110010 in binary. 
  3. $b = 30; //11110 in binary.
  4. $c = 0;
  5. $d = 0; // $ use for variables.
  6. $e = 0;
  7. $f = 0;
  8. $g = 0;
  9. $h = 0;

  10. //Bitwise AND
  11. $c = $a & $b; // 110010 & 11110 = 10010 i.e means is '18'.
  12. echo ("The value of AND is:- $c <br>");

  13. //Bitwise OR
  14. $d = $a | $b; // 110010 | 11110 = 111110 i.e means is '62'.
  15. echo ("The value of OR is:- $d <br>");  // <br> use for linebreake

  16. //Bitwise Exclusive XOR
  17. $e = $a ^ $b;
  18. echo ("The value of Exclusive OR is:- $e <br>"); // echo use for print line.

  19. //Bitwise Complement
  20. $f = ~$a; // -(50+1)= i.e means is '-51'.
  21. echo ("The value of Complement is:- $f <br>");  // .$c. is used to indicate which value should be print.

  22. //Bitwise Shift Left
  23. $g = $a << 2; //50=110010 << 2 :- 11001000 i.e means is '200'. //Shift with 2 zero to left side.
  24. echo ("The value of Shift Left is:- $g <br>");

  25. //Bitwise Shift Right
  26. $h = $a >> 2; // 50=110010 >> 2 :-  001100 i.e means os '12'. //Shift with 2 zero to right side.
  27. echo ("The value of Shift Right  is:- $h <br>");

//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 Shift Right is:- 12

*/






//ThE ProFessoR

?>