<?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);
PD9waHAKCmZ1bmN0aW9uIGJpbjJzaSgkYmluLCRiaXRzPTMyKSAKeyAKICAgIGlmIChzdHJsZW4oJGJpbik9PSRiaXRzKSAKICAgIHsgCiAgICAgICAgaWYgKHN1YnN0cigkYmluLDAsMSkgPT0gMCkgLy8gcG9zaXRpdmUgb3IgemVybyAKICAgICAgICB7IAogICAgICAgICAgICAkc2kgPSBiYXNlX2NvbnZlcnQoJGJpbiwyLDEwKTsgCiAgICAgICAgfSAKICAgICAgICBlbHNlIC8vIG5lZ2F0aXZlIAogICAgICAgIHsgCiAgICAgICAgICAgICRzaSA9IGJhc2VfY29udmVydCgkYmluLDIsMTApOyAKICAgICAgICAgICAgJHNpID0gLShwb3coMiwkYml0cyktJHNpKTsgCiAgICAgICAgfSAKICAgICAgICByZXR1cm4gJHNpOyAKICAgIH0gCn0gCgplY2hvIGJpbjJzaSgnMTExMTExMDEnLCA4KTs=