Class BaseConverter
Arbitrary precision number base converter.
BaseConverter provides convenience to number conversion by providing a method
that accepts numbers as strings in addition to selecting the appropriate
number conversion strategy based on the provided number bases (which may also
be provided as constructor arguments for NumberBase instead of instances of
the said class).
BaseConverter can also be used as a simple replacement for PHP's built in
base_convert()
via the provided static method that accepts arguments
similar to the built in function in addition to providing the extra features
of this library (such as arbitrary precision conversion and support for
fractions).

Riimu\Kit\BaseConversion\BaseConverter
implements
Riimu\Kit\BaseConversion\Converter
Methods summary
public

#
__construct( mixed $sourceBase, mixed $targetBase )
Creates a new instance of BaseConverter.
Creates a new instance of BaseConverter.
The source and target number bases can be provided either as an instance
of the NumberBase class or as constructor arguments that are provided to
the NumberBase class.
The constructor will select the most optimal conversion strategy based
on the provided number bases.
Parameters
 $sourceBase
 Number base used by the provided numbers
 $targetBase
 Number base used by the returned numbers
See

public static
stringfalse

#
baseConvert( string $number, mixed $fromBase, mixed $toBase, integer $precision = 1 )
Converts the provided number from base to another.
Converts the provided number from base to another.
This method provides a convenient replacement to PHP's built in
base_convert() . The number bases are simply passed along to the
constructor, which means they can be instances of NumberBase class or
constructor parameters for that class.
Note that due to the way the constructor parameters for NumberBase work,
this method can be used exactly the same way as base_convert() .
Parameters
 $number
 The number to convert
 $fromBase
 Number base used by the provided number
 $toBase
 Number base used by the returned number
 $precision
 Precision for inaccurate conversion
Returns
stringfalse The converted number or false on error

public
stringfalse

#
convert( string $number )
Converts the number provided as a string from source base to target base.
Converts the number provided as a string from source base to target base.
This method provides convenient conversions by accepting the number as
a string. The number may optionally be preceded by a plus or minus sign
which is prepended to the result as well. The number may also have a
period, which separates the integer part and the fractional part.
Due to the special meaning of + ,  and . , it is not recommended to
use this method to convert numbers when using number bases that have a
meaning for these characters (such as base64).
If the number contains invalid characters, the method will return false
instead.
Parameters
 $number
 The number to convert
Returns
stringfalse The converted number or false on error

public

#
setPrecision( integer $precision )
Sets the precision for inaccurate fraction conversions.
Sets the precision for inaccurate fraction conversions.
The fractions cannot always be accurately converted from base to another,
since they may represent a fraction that cannot be represented in another
number base. The precision value is used to determine the number of
digits in the fractional part, if the number cannot be accurately
converted or if it is not feasible to determine that.
If the precision is positive, it defines the maximum number of digits in
the fractional part. If the value is 0, the converted number will have
at least as many digits in the fractional part as it takes to represent
the number in the same accuracy as the original number. A negative number
will simply increase the number of digits.
Note that the fractional part may have fewer digits than what is required
by the precision if it can be accurately represented using fewer digits.
Parameters
 $precision
 Precision used for inaccurate conversions.
Implementation of

public
array

#
convertInteger( array $number )
Converts the integer part of a number.
Converts the integer part of a number.
The integer part should be provided as an array of digits with least
significant digit first. Any invalid digit in the array will cause an
exception to be thrown. The return value will be a similar array of
digits, except converted to the target number base.
Parameters
 $number
 Array of digits representing the integer part
Returns
array Digits for the converted number
Throws
Implementation of

public
array

#
convertFractions( array $number )
Converts the fractional part of a number.
Converts the fractional part of a number.
The fractional part should be provided as an array of digits with least
significant digit first. Any invalid digit in the array will cause an
exception to be thrown. The return value will be a similar array of
digits, except converted to the target number base.
Parameters
 $number
 Array of digits representing the fractional part
Returns
array Digits for the converted number
Throws
Implementation of
