|
Posted by Hilarion on 06/24/05 18:08
Andy Hassall wrote:
> > for ($i=0; $i<46656; $i++)
> > echo base_convert($i, 10, 36). "<br>";
Marcos wrote:
> Sorry, but I am curious. And I'd like to know how this work. I still did
> not undertand very well.
How what works? The function "base_convert" takes a string (first param)
representing a number with given base (in second param) and converts
it to a string representing same number in another base (given in third
param).
executing this | means this
--------------------------------+------------------------------------
base_convert( '1234', 10, 2 ) | convert decimal 1234 to binary
base_convert( '1010', 2, 8 ) | convert binary 1010 to octal
base_convert( '1FEA', 16, 2 ) | convert hexadecimal 1FEA to binary
You can use any base between 2 and 36. The base_convert uses decimal digits
from '0' to '9' and base letters (from 'A' to 'Z' - it does not matter
if letter is capital or not) giving them values from 0 to 9 (for digits)
and from 10 to 35 (for letters). This 36 digit set is truncated for
the specified base, so for binary input / output we have 0 and 1, for
octal - 0, 1, 2, 3, 4, 5, 6, 7, for decimal from 0 to 9, for hexadecimal
- 0..9, A, B, C, D, E, F.
The first parameter is converted to string, so base_convert( 1010, 2, 8 )
gives same result as base_convert( '1010', 2, 8 ).
Hilarion
[Back to original message]
|