Learn the PHP conversion, there are a lot of knowledge points, logic, but also the most primitive written calculation, but we are accustomed to use code to implement the conversion, the conversion code is as follows: binary (BIN) octal (Oct) decimal (dec) hex (hex)
Examples of specific conversion and use methods and instructions are as follows: Convert binary to decimal bindec, convert decimal to octal decoct, convert decimal to hexadecimal dechex,
The sample code is as follows:
Example 1.
PHP output 20 decimal number, octal number, hexadecimal number */
$i = 20;
printf ("%d", $i);//%d = 10 binary
echo "<br/>";
printf ("%o", $i);//%0 = 8 binary
echo "<br/>";
printf ("%x", $i);//%x represents 16 binary
Example 2.
Write the conversion method between 2, 8, and 16 binary. Write down the following results
(binary number) 11100101011 = (octal number) = (hexadecimal number)
$a =bindec (11100101011);//convert binary 11100101011 to decimal using BINDEC.
echo $a; Output a value of 11100101011 in decimal
echo "<br/>";
echo decoct ($a);//convert decimal to octal using DECOCT.
echo "<br/>";
Example 3.
Write the binary turn 10 binary method and the 10 binary to 2 binary method, write the following results
(binary number) 101011100011001 = (decimal number)
(decimal number) 456 = (binary number
/*echo bindec (' 101011100011001 ');//Remember to add double quotation marks otherwise the result is problematic.
echo "<br/>";
echo decbin (' 456 ');
Conversion of PHP into binary