note 106217 added to function.base-convert

From: Date: Wed, 19 Oct 2011 12:55:13 +0000
Subject: note 106217 added to function.base-convert
Groups: php.notes 
Request: Send a blank email to php-notes+get-183995@lists.php.net to get a copy of this message
The example below don't works. <?php function intToAlphaBaseN($n,$baseArray) { $l=count($baseArray); $s = ''; for ($i = 1; $n >= 0 && $i < 10; $i++) { $s = $baseArray[($n % pow($l, $i) / pow($l, $i - 1))].$s; $n -= pow($l, $i); } return $s; } function alphaBaseNToInt($nab,$baseArray) { $l = count($baseArray); $b = strlen($nab); $s = 0; $values = array(); foreach ($baseArray as $key => $value) $values[$value] = $key ; for ($i = 0; $i < $b; $i++) $s += ($values[$nab[$i]] * pow($l, $b - $i - 1)); return $s; } $alpha = array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ); $r=rand(0, 99999999999);//if we consider 426596311 as input number echo($r = intToAlphaBaseN($r,$alpha));// returns a different number also if the base is the same echo(alphaBaseNToInt($r,$alpha));// reverse function works ?> ---- Server IP: 69.147.83.197 Probable Submitter: 89.97.196.36 ---- Manual Page -- http://www.php.net/manual/en/function.base-convert.php Edit -- https://master.php.net/note/edit/106217 Del: integrated -- https://master.php.net/note/delete/106217/integrated Del: useless -- https://master.php.net/note/delete/106217/useless Del: bad code -- https://master.php.net/note/delete/106217/bad+code Del: spam -- https://master.php.net/note/delete/106217/spam Del: non-english -- https://master.php.net/note/delete/106217/non-english Del: in docs -- https://master.php.net/note/delete/106217/in+docs Del: other reasons-- https://master.php.net/note/delete/106217 Reject -- https://master.php.net/note/reject/106217 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183995) next »