<?php
function bin2si($bin, $bits = 32) {
if (substr($bin,0,1) == 0) { // positive or zero } else { // negative
$si = -(pow(2,$bits)-$si); }
return $si;
}
}
echo bin2si('11111101', 8);
//https://pt.stackoverflow.com/q/78335/101
PD9waHAKCmZ1bmN0aW9uIGJpbjJzaSgkYmluLCAkYml0cyA9IDMyKSB7IAogICAgaWYgKHN0cmxlbigkYmluKSA9PSAkYml0cykgeyAKICAgICAgICBpZiAoc3Vic3RyKCRiaW4sMCwxKSA9PSAwKSB7IC8vIHBvc2l0aXZlIG9yIHplcm8gCiAgICAgICAgICAgICRzaSA9IGJhc2VfY29udmVydCgkYmluLDIsMTApOyAKICAgICAgICB9IGVsc2UgeyAvLyBuZWdhdGl2ZSAKICAgICAgICAgICAgJHNpID0gYmFzZV9jb252ZXJ0KCRiaW4sMiwxMCk7IAogICAgICAgICAgICAkc2kgPSAtKHBvdygyLCRiaXRzKS0kc2kpOyAKICAgICAgICB9IAogICAgICAgIHJldHVybiAkc2k7IAogICAgfSAKfSAKCmVjaG8gYmluMnNpKCcxMTExMTEwMScsIDgpOwoKLy9odHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvNzgzMzUvMTAx