note 72141 deleted from function.dechex by bobby
| From: | bobby@php.net | Date: | Thu, 04 Jan 2007 15:07:51 +0000 |
| Subject: | note 72141 deleted from function.dechex by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121283@lists.php.net to get a copy of this message | ||
Note Submitter: black_m4niac at yahoo dot com
----
<?
function dec2hex($dec)
{
$dec=intval($dec);
for($i=0;$i<=11;$i++)
if($dec > pow(16,$i) && $dec < pow(16,$i+1))
$pow=$i;
$hex="";
while($pow>=0)
{
$cat=intval($dec/pow(16,$pow));
switch( intval($dec/pow(16,$pow)) )
{
case 10:
$hex.="a";
break;
case 11:
$hex.="b";
break;
case 12:
$hex.="c";
break;
case 13:
$hex.="d";
break;
case 14:
$hex.="e";
break;
case 15:
$hex.="f";
break;
default:
$hex.=$cat;
}
$dec-=$cat*pow(16,$pow);
$pow--;
}
return $hex;
}
echo "dec2hex('2007') - ".dec2hex('2007');
echo "<br>dec2hex(2007) - ".dec2hex(2007);
echo "<br>dechex(2007) - ".dechex(2007);
?>