Exemple #1
0
 /**
  * Converts a number from one base into another. May be called statically.
  * 
  * @param mixed number The number to convert
  * @param int from_base The base to convert from
  * @param int to_base The base to convert to
  * @param string from_cs Optional character set of the number that is
  *                                converted
  * @param string to_cs Optional character set of the target number
  * @return string
  * @access public
  */
 function baseConvert($number, $from_base, $to_base, $from_cs = null, $to_cs = null)
 {
     if (isset($this)) {
         $obj =& $this;
     } else {
         $obj =& Math_Basex::instance();
     }
     if (!isset($from_cs)) {
         $from_cs = $obj->stdBase();
     }
     if (!isset($to_cs)) {
         $to_cs = $obj->stdBase();
     }
     if (strlen($from_cs) < $from_base) {
         return PEAR::raiseError('Character set isn\'t long enough for the' . 'given base.');
     }
     if (strlen($to_cs) < $to_base) {
         return PEAR::raiseError('Character set isn\'t long enough for the' . 'given base.');
     }
     $from_cs = substr($from_cs, 0, $from_base);
     $to_cs = substr($to_cs, 0, $to_base);
     if ($tmp = $obj->setBase($from_cs) !== true) {
         return $tmp;
     }
     $number = $obj->toDecimal($number);
     if (PEAR::isError($number)) {
         return $number;
     }
     if ($tmp = $obj->setBase($to_cs) !== true) {
         return $tmp;
     }
     $number = $obj->toBase($number);
     return $number;
 }