signed 8 bit to "sign and magnitude" handler needed [PART ONE]

stephen barncard stephenREVOLUTION2 at barncard.com
Thu Mar 17 15:02:27 EDT 2011


<this is part two>

I found the below PHP code online that seemed appropriate and tried to
convert it to Livecode but it didn't return useful values.

(not sure if I needed [$num = bindec($bin);] - turns number into string?)


/*

-- original PHP version found online and not tested in PHP

function _bin8dec($bin) {

    // function to convert 8bit binary numbers to integers using two's
complement

    $num = bindec($bin);

    if($num > 0xFF) { return false; }

    if($num >= 0x80) {

        return -(($num ^ 0xFF)+1);

    } else {

        return $num;

    }

} ?>


*/


function bin8dec pBinary

      // does not crash, but returns useless values

      // function to convert 8bit binary numbers to integers using two's
complement

      --   [  $num = bindec($bin);   ]  not needed - php for convert to
string ?

      if pBinary > 0xFF then return false

      if pBinary >= 0x80

      then

            return -(( pBinary ^ 0xFF)+1);

      else

            return pBinary

      end if

end bin8dec


thanks in advance for any help..


sqb


On 17 March 2011 12:00, stephen barncard <stephenREVOLUTION2 at barncard.com>wrote:

> This isn't that long a message but it appears I've pushed the limit.
> THis is part one.
>
>
Stephen Barncard
San Francisco Ca. USA

more about sqb  <http://www.google.com/profiles/sbarncar>



More information about the use-livecode mailing list