How to get the minimum (min) of two integers with bitwise operators in PHP

1 Answer

0 votes
$x = 3;
$y = -9;            
  
$min = $y ^ (($x ^ $y) & -($x < $y)); 
echo $min . "<br />";
      
$x = 5;
$y = 2;
      
$min = $y ^ (($x ^ $y) & -($x < $y));  
echo $min . "<br />";
      
 
   
/*
run:
        
-9
2
       
*/

 



answered Mar 24, 2019 by avibootz
...