fork(2) download
  1. <?php
  2.  
  3. function bin2si($bin,$bits=32)
  4. {
  5. if (strlen($bin)==$bits)
  6. {
  7. if (substr($bin,0,1) == 0) // positive or zero
  8. {
  9. $si = base_convert($bin,2,10);
  10. }
  11. else // negative
  12. {
  13. $si = base_convert($bin,2,10);
  14. $si = -(pow(2,$bits)-$si);
  15. }
  16. return $si;
  17. }
  18. }
  19.  
  20. echo bin2si('11111101', 8);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
-3