PHP comes with built-in functions for converting between binary,decimal,octal,and hexadecimal bases.Here's an example which demonstrates the bindex(),decbin(),decoct(),dechex(),hexdex(),and octdec() functions in action:
------------------------------------------------------------------------
<?php
//convert to binary
//output:1000
echo decbin(8);
//convert to hexadecimal
//output:8
echo dechex(8);
//....10
echo decoct(8)
//...8
echo octdex(10);
//...101
echo hexdec(65);
//...8
echo bindex(1000);
//8,specified as octal value
$a=010;
//1500,specified as hexadecimal value
$b=0x5dc;
//690,in scientific notation
$c=6.9E+2;
?>
------------------------------------------------------------------------
<?php
//convert to binary
//output:1000
echo decbin(8);
//convert to hexadecimal
//output:8
echo dechex(8);
//....10
echo decoct(8)
//...8
echo octdex(10);
//...101
echo hexdec(65);
//...8
echo bindex(1000);
//8,specified as octal value
$a=010;
//1500,specified as hexadecimal value
$b=0x5dc;
//690,in scientific notation
$c=6.9E+2;
?>