note 94400 deleted from function.dechex by danbrown
| From: | danbrown@php.net | Date: | Tue, 16 Feb 2010 23:26:30 +0000 |
| Subject: | note 94400 deleted from function.dechex by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166032@lists.php.net to get a copy of this message | ||
Note Submitter: gsmalarmsys.com
----
Thanks to jbleau at gmail dot com for great script. But but it does not return correct results,
because Modulus for example 78559093562500%16 returns -12, but not 4 (i'll post about this bug
too).
But for now the working script is:
<?php
function dec_to_hex($dec)
{
$sign = $h = ""; // suppress errors. '$h' is added by Mozg
if( $dec < 0){ $sign = "-";
$dec = abs($dec); }
$hex = Array( 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5,
6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 'a',
11 => 'b', 12 => 'c', 13 => 'd', 14 =>
'e',
15 => 'f' );
do
{
$mozg = $dec%16; if ($mozg < 0) $mozg += 16; // Checking if Modulus is positive? and
corrects its "inertia". added by Mozg
$h = $hex[$mozg] . $h;
$dec /= 16;
}
while( $dec >= 1 );
return $sign . $h;
}
?>