php method to convert integers to hexadecimal: 1. Use the dechex() function, the syntax "dechex (integer value)"; 2. Use the base_convert() function, the syntax "bindec (integer value, 10 , 16)”.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php will integer ( Decimal number) to hexadecimal
1. Use the dechex() function
Usedechex(integer value)
Function, which converts decimal numbers to hexadecimal numbers.
<?php echo dechex(10) . "<br>"; echo dechex(20) . "<br>"; echo dechex(1587) . "<br>"; echo dechex(70); ?>
Output result:
2. Use base_convert() function
Use base_convert() function to To convert numbers between any bases, just set "bindec(integer value, 10, 16)
".
<?php echo base_convert(30, 10, 16) . "<br>"; echo base_convert(10, 10, 16) . "<br>"; echo base_convert(1587, 10, 16) . "<br>"; echo base_convert(70, 10, 16); ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert integer to hexadecimal in php. For more information, please follow other related articles on the PHP Chinese website!