Home  >  Article  >  Backend Development  >  How to convert integer to hexadecimal in php

How to convert integer to hexadecimal in php

青灯夜游
青灯夜游Original
2022-02-14 19:44:452527browse

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)”.

How to convert integer to hexadecimal in php

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:

How to convert integer to hexadecimal in php

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:

How to convert integer to hexadecimal in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn