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