note 99257 deleted from function.dechex by danbrown
| From: | danbrown@php.net | Date: | Fri, 06 Aug 2010 13:55:41 +0000 |
| Subject: | note 99257 deleted from function.dechex by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171432@lists.php.net to get a copy of this message | ||
Note Submitter: J.M. van Leeuwen
----
Here's another solution to 'extend' dechex's size limitation. This supports also
values > 2.147.483.648, but doesn't support signs because I only used positive numbers in
the script where I used this function.
function
dec2hex($dec,$hex=array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f')){
for($h='',$r=$dec;$r>15;){
// $r%16 is inaccurate when using bigger values, like 11.435.168.214!
$n = floor($r/16); $h = $hex[($r-$n*16)].$h; $r = $n;
}
return $hex[($r%16)].$h;
}