Conversion method: 1. Use dechex() to convert decimal to hexadecimal, the syntax is "dechex (decimal value)"; 2. Use base_convert(), the syntax is "bindec(decimal value, 10 ,16)"; 3. Use bin2hex(), the syntax is "bin2hex (string)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php converts data Is hexadecimal
1. Use the dechex() function - you can convert decimal to hexadecimal
dechex (decimal value)
can convert decimal numbers into hexadecimal numbers.
<?php echo dechex("30") . "<br>"; echo dechex("10") . "<br>"; echo dechex("1587") . "<br>"; echo dechex("70"); ?>
Output result:
1e a 633 46
2. Use the base_convert() function--to convert decimal to hexadecimal
base_convert() Function converts numbers between arbitrary bases.
Set "bindec(decimal value, 10, 16)
" to convert decimal to hexadecimal.
<?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:
3. Use the bin2hex() function--convert the string to hexadecimal
bin2hex(string)
Function converts a string of ASCII characters into a hexadecimal value.
<?php $str = bin2hex("Hello World!"); echo($str); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert data to hexadecimal in php. For more information, please follow other related articles on the PHP Chinese website!