Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Dedicated Hosting Superb Internet

simplilearn big data and analytics

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Buy Cool Shirts

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,300 questions

8,938 answers

573 users

How to use binary bitwise assignment operators in PHP

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial


10 views
asked Sep 6 by avibootz

1 Answer

0 votes
$n = 0b110111;  
echo "\$n = 0b110111 = " . $n . "<br /><br />";

// bitwise and
echo "&nbsp;&nbsp;&nbsp;&nbsp;" . decbin($n) . 
     "<br />& 101001 <br />------------<br />&nbsp;&nbsp;&nbsp;&nbsp;" . 
     decbin($n &= 0b101001). " = $n<br /><br />";

// bitwise or
echo "&nbsp;&nbsp;" . decbin($n) . 
     "<br />| 110101 <br />------------<br />&nbsp;&nbsp;" . 
     decbin($n |= 0b110101). " = $n<br /><br />";

// bitwise xor
echo "&nbsp;&nbsp;&nbsp;" . 
     decbin($n) . "<br />^ 000110 <br />------------<br />&nbsp;&nbsp;&nbsp;" . 
     decbin($n ^= 0b000110). " = $n<br /><br />";

// shift right by 2
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 
     decbin($n) . "<br />>> 2 <br />------------<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 
     decbin($n >>= 2). " = $n<br /><br />";
      
// shift left by 1
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 
     decbin($n) . "<br /><< 1 <br />------------<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 
     decbin($n <<= 1). " = $n<br /><br />";
  

 
/*
run: 
  
$n = 0b110111 = 55

  110111
& 101001 
------------
  100001 = 33

  100001
| 110101 
------------
  110101 = 53

  110101
^ 000110 
------------
  110011 = 51

   110011
>> 2 
------------
   1100 = 12

   1100
<< 1 
------------
   11000 = 24
  
*/  

 




answered Sep 6 by avibootz
...