note 94400 added to function.dechex
| From: | gsmalarmsys dot com at osu1 dot php dot net | Date: | Mon, 02 Nov 2009 21:02:00 +0000 |
| Subject: | note 94400 added to function.dechex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162343@lists.php.net to get a copy of this message | ||
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:
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;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 90.191.206.241
----
Manual Page -- http://www.php.net/manual/en/function.dechex.php
Edit -- https://master.php.net/note/edit/94400
Del: integrated -- https://master.php.net/note/delete/94400/integrated
Del: useless -- https://master.php.net/note/delete/94400/useless
Del: bad code -- https://master.php.net/note/delete/94400/bad+code
Del: spam -- https://master.php.net/note/delete/94400/spam
Del: non-english -- https://master.php.net/note/delete/94400/non-english
Del: in docs -- https://master.php.net/note/delete/94400/in+docs
Del: other reasons-- https://master.php.net/note/delete/94400
Reject -- https://master.php.net/note/reject/94400
Search -- https://master.php.net/manage/user-notes.php