note 97102 added to function.bindec

From: Date: Thu, 01 Apr 2010 12:40:51 +0000
Subject: note 97102 added to function.bindec
Groups: php.notes 
Request: Send a blank email to php-notes+get-167615@lists.php.net to get a copy of this message
Two functions to convert 16bit or 8bit binary to integer using two's complement. If input exceeds maximum bits, false is returned. Function is easily scalable to x bits by changing the hexadecimals. <?php function _bin16dec($bin) { // Function to convert 16bit binary numbers to integers using two's complement $num = bindec($bin); if($num > 0xFFFF) { return false; } if($num >= 0x8000) { return -(($num ^ 0xFFFF)+1); } else { return $num; } } 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; } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 131.155.174.177 ---- Manual Page -- http://www.php.net/manual/en/function.bindec.php Edit -- https://master.php.net/note/edit/97102 Del: integrated -- https://master.php.net/note/delete/97102/integrated Del: useless -- https://master.php.net/note/delete/97102/useless Del: bad code -- https://master.php.net/note/delete/97102/bad+code Del: spam -- https://master.php.net/note/delete/97102/spam Del: non-english -- https://master.php.net/note/delete/97102/non-english Del: in docs -- https://master.php.net/note/delete/97102/in+docs Del: other reasons-- https://master.php.net/note/delete/97102 Reject -- https://master.php.net/note/reject/97102 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167615) next »