home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / convert_base.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  805 b   |  29 lines

  1. <?php
  2.  
  3. //Include BaseX class
  4. include_once( "Math/Basex.php" );
  5.  
  6. //mirror HEX character set an convert current code to new code
  7. $newcode = convert_base("5c", "012345679abcdef", "fedcba9876543210");
  8. echo $newcode . " (Result: a9)\n";
  9. $newcode = Math_Basex::baseConvert("14", 10, 2);
  10. echo $newcode . " (Result: 1110)\n";
  11.  
  12.  
  13. function convert_base($code, $oldbase, $newbase)
  14. {
  15.     // take old base an input
  16.      $base = new Math_Basex($oldbase);
  17.         
  18.     //convert code to base10 decimal number
  19.     $number = $base->toDecimal($code);
  20.                 
  21.     //change to the new base
  22.     $base->setBase($newbase);
  23.                         
  24.     //encode the decimal number and return the result to the function
  25.     return $base->toBase($number);
  26. }
  27.                                                                 
  28. ?>
  29.