Home > Article > Backend Development > What are the functions for converting php to binary?
php functions to convert to binary: 1. The decbin() function can convert decimal numbers to binary, the syntax is "decbin (decimal value)"; 2. The base_convert() function can convert any decimal value Convert to binary, the syntax is "bindec(arbitrary base value, original base number, 2)".
The operating environment of this tutorial: Windows7 system, PHP7. Version 1, DELL G3 computer
There are two functions for converting php to binary:
decbin() function
base_convert() function
#1. Use the decbin() function
The decbin() function can convert decimal numbers into Binary numbers.
<?php echo decbin(3) . "<br>"; echo decbin(1) . "<br>"; echo decbin(1587) . "<br>"; echo decbin(7); ?>
#2. Use the base_convert() function
The base_convert() function can be used between any bases Conversion, convert the specified original base system into the target base system, just set the original base system and the base system to be converted.
<?php echo base_convert(2,10,2) . "<br>"; echo base_convert("cceeff",16,2) . "<br>"; echo base_convert("JZG8X",36,2) . "<br>"; echo base_convert("2003001",17,2); ?>
Recommended learning: "PHP video tutorial》
The above is the detailed content of What are the functions for converting php to binary?. For more information, please follow other related articles on the PHP Chinese website!