PHP Classes

Easy readingPHP Convert Number to Base: Convert numbers between base 10 to another base

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 49 All time: 10,738 This week: 206Up
Version License PHP version Categories
toolconvert 1.0Public Domain5PHP 5, Conversion, Math, Traits
Description 

Author

This class can convert numbers between base 10 to another base.

It can take a number and converts it from base 10 to another base.

The class can also convert a string that represents a number in a given base and converts it to base 10.

It also has a function that gets the next number after converting to the specific base.

Picture of Mundo Genesys Development
  Performance   Level  
Name: Mundo Genesys ... <contact>
Classes: 2 packages by
Country: Mexico Mexico
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Example

<?php

ini_set
('display_errors', true);
error_reporting(E_ERROR | E_PARSE | E_NOTICE | E_WARNING);

include_once(
"class.php");
$demo=new MyClass();

echo
"********** <br> Use with original base (62, number & letter upper case & letter lower case) <br> ********** <br> <br>";

echo
"<br> 14: "; $tmp = $demo->ot_tobase(14);echo $tmp." <br>";
echo
"<br> 61: "; $tmp = $demo->ot_tobase(61);echo $tmp." <br>";
echo
"<br> 62: "; $tmp = $demo->ot_tobase(62);echo $tmp." <br>";
echo
"<br> 960: "; $tmp = $demo->ot_tobase(960);echo $tmp." <br>";
echo
"<br> 3476: "; $tmp = $demo->ot_tobase(3476);echo $tmp." <br>";
echo
"<br> 36247: "; $tmp = $demo->ot_tobase(36247);echo $tmp." <br>";

echo
"********** <br> change to base 36 (number & letter upper case) <br> ********** <br> <br>";

$demo->ot_changebase(36);

echo
"<br> 14: "; $tmp = $demo->ot_tobase(14);echo $tmp." <br>";
echo
"<br> 61: "; $tmp = $demo->ot_tobase(61);echo $tmp." <br>";
echo
"<br> 62: "; $tmp = $demo->ot_tobase(62);echo $tmp." <br>";
echo
"<br> 960: "; $tmp = $demo->ot_tobase(960);echo $tmp." <br>";
echo
"<br> 3476: "; $tmp = $demo->ot_tobase(3476);echo $tmp." <br>";
echo
"<br> 36247: "; $tmp = $demo->ot_tobase(36247);echo $tmp." <br>";

echo
"********** <br> change to Hexa (number & A B C D E F) <br> ********** <br> <br>";

$demo->ot_changebase(15);

echo
"<br> 14: "; $tmp = $demo->ot_tobase(14);echo $tmp." <br>";
echo
"<br> 61: "; $tmp = $demo->ot_tobase(61);echo $tmp." <br>";
echo
"<br> 62: "; $tmp = $demo->ot_tobase(62);echo $tmp." <br>";
echo
"<br> 960: "; $tmp = $demo->ot_tobase(960);echo $tmp." <br>";
echo
"<br> 3476: "; $tmp = $demo->ot_tobase(3476);echo $tmp." <br>";
echo
"<br> 36247: "; $tmp = $demo->ot_tobase(36247);echo $tmp." <br>";

echo
"********** <br> change to Binary <br> ********** <br> <br>";

$demo->ot_changebase(2);

echo
"<br> 14: "; $tmp = $demo->ot_tobase(14);echo $tmp." <br>";
echo
"<br> 61: "; $tmp = $demo->ot_tobase(61);echo $tmp." <br>";
echo
"<br> 62: "; $tmp = $demo->ot_tobase(62);echo $tmp." <br>";
echo
"<br> 960: "; $tmp = $demo->ot_tobase(960);echo $tmp." <br>";
echo
"<br> 3476: "; $tmp = $demo->ot_tobase(3476);echo $tmp." <br>";
echo
"<br> 36247: "; $tmp = $demo->ot_tobase(36247);echo $tmp." <br>";


echo
"********** <br> To decimal from original base (62, number & letter upper case & letter lower case) <br> ********** <br> <br>";

$demo->ot_changebase(62);

echo
"<br> E: "; $tmp = $demo->ot_tobase10('E');echo $tmp." <br>";
echo
"<br> z: "; $tmp = $demo->ot_tobase10('z');echo $tmp." <br>";
echo
"<br> 10: "; $tmp = $demo->ot_tobase10('10');echo $tmp." <br>";
echo
"<br> FU: "; $tmp = $demo->ot_tobase10('FU');echo $tmp." <br>";
echo
"<br> u4: "; $tmp = $demo->ot_tobase10('u4');echo $tmp." <br>";
echo
"<br> 9Qd: "; $tmp = $demo->ot_tobase10('9Qd');echo $tmp." <br>";

echo
"********** <br> Get Next in original base (62, number & letter upper case & letter lower case) <br> ********** <br> <br>";
echo
"<br> E: "; $tmp = $demo->ot_next('E');echo $tmp." <br>";
echo
"<br> z: "; $tmp = $demo->ot_next('z');echo $tmp." <br>";
echo
"<br> 10: "; $tmp = $demo->ot_next('10');echo $tmp." <br>";
echo
"<br> FU: "; $tmp = $demo->ot_next('FU');echo $tmp." <br>";
echo
"<br> u4: "; $tmp = $demo->ot_next('u4');echo $tmp." <br>";
echo
"<br> 9Qd: "; $tmp = $demo->ot_next('9Qd');echo $tmp." <br>";



echo
'Demo Finish';
?>


Details

This class, permit change decimal integer number to diferent numeric representation, since binary to base 62, can obtain next number in the select base, is a perfect way to have easy read of id, is write like a trait so just nedd copy in ur proyect and use


  Files folder image Files (4)  
File Role Description
Plain text file class.php Class Class source
Accessible without login Plain text file DemoConvert.php Example Example script
Plain text file myclass.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:49
This week:0
All time:10,738
This week:206Up