Home > Backend Development > PHP Problem > How to convert integer to hexadecimal in php

How to convert integer to hexadecimal in php

青灯夜游
Release: 2023-03-15 10:48:02
Original
2615 people have browsed it

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);
?>
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template