Home  >  Article  >  Backend Development  >  How to convert php string to decimal

How to convert php string to decimal

藏色散人
藏色散人Original
2020-08-18 09:19:474333browse

In PHP, you can convert a hexadecimal string to decimal through the hexdec function. The syntax of this function is "hexdec(hex_string)", where the parameter "hex_string" represents the hexadecimal number to be converted. .

How to convert php string to decimal

Recommended: "PHP Video Tutorial"

hexdec() function converts hexadecimal to decimal.

Syntax

hexdec(hex_string)

Parameters

hex_string Required. Specifies the hexadecimal number to be converted.

Description

Returns the decimal number equivalent to the hexadecimal number represented by the hex_string parameter. hexdec() Converts a hexadecimal string to a decimal number. The maximum value that can be converted is 7ffffffff, which is 2147483647 in decimal. Starting with PHP 4.1.0, this function can handle large numbers, in which case it returns a float type.

hexdec() Replaces all non-hexadecimal characters encountered with 0. This way, all zeros on the left are ignored, but zeros on the right are included in the value.

Example

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

Output:

30
10
4607
13430527

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