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

How to convert hexadecimal to decimal in php

青灯夜游
青灯夜游Original
2022-02-15 13:51:365010browse

php method to convert hexadecimal to decimal: 1. Use hexdec() function, syntax "hexdec("hexadecimal value")"; 2. Use base_convert() function, syntax " base_convert("hex value", 16, 10)".

How to convert hexadecimal to decimal in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php will be sixteen Convert hexadecimal to decimal

1. Use the hexdec() function

hexdec (hexadecimal string) Function can convert hexadecimal numbers to decimal numbers.

<?php
echo hexdec("1e") . "<br>";
echo hexdec("a") . "<br>";
echo hexdec("11ff") . "<br>";
echo hexdec("cceeff");
?>

How to convert hexadecimal to decimal in php

2. Use the base_convert() function

base_convert() function to convert numbers between any bases, just Set "bindec(hex string, 16, 10)" to convert hexadecimal numbers into decimal numbers.

<?php
echo base_convert("1e", 16, 10) . "<br>";
echo base_convert("a", 16, 10) . "<br>";
echo base_convert("11ff", 16, 10) . "<br>";
echo base_convert("cceeff", 16, 10);
?>

How to convert hexadecimal to decimal in php

Description:

base_convert() function converts numbers between arbitrary bases. Syntax:

base_convert(number,frombase,tobase);
  • number Required. Specifies the number to be converted.​

  • #frombase Required. Specifies the original base of the number. Between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35.​

  • #tobase Required. Specifies the base to be converted. Between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35.

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to convert hexadecimal to decimal 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