note 89016 added to function.octdec
| From: | cubbo at quakenet dot php | Date: | Wed, 18 Feb 2009 13:49:52 +0000 |
| Subject: | note 89016 added to function.octdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150793@lists.php.net to get a copy of this message | ||
Hi, this is an attempt to explain octdec().
There is one bug, if input is not octal, it doesn't return a proper decimal.
<?php
$octal = (int) "764";
function octal_to_decimal($int)
{
$data = integer;
$i = (strlen($int) - 1);
$parse_int = str_split($int);
foreach($parse_int as $value)
{
$data += (int)($value * pow(8, $i));
$i--;
}
return $data;
}
/**
* explanation of the PHP function octdec()
*/
print octal_to_decimal($octal) . "<br />";
/**
* the PHP function octdec()
*/
print octdec($octal);
?>
----
Server IP: 92.48.74.199
Probable Submitter: 217.41.34.61
----
Manual Page -- http://www.php.net/manual/en/function.octdec.php
Edit -- https://master.php.net/note/edit/89016
Del: integrated -- https://master.php.net/note/delete/89016/integrated
Del: useless -- https://master.php.net/note/delete/89016/useless
Del: bad code -- https://master.php.net/note/delete/89016/bad+code
Del: spam -- https://master.php.net/note/delete/89016/spam
Del: non-english -- https://master.php.net/note/delete/89016/non-english
Del: in docs -- https://master.php.net/note/delete/89016/in+docs
Del: other reasons-- https://master.php.net/note/delete/89016
Reject -- https://master.php.net/note/reject/89016
Search -- https://master.php.net/manage/user-notes.php