Home > Backend Development > PHP Problem > How to convert php string to decimal

How to convert php string to decimal

藏色散人
Release: 2023-03-04 16:50:01
Original
4406 people have browsed it

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

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

Output:

30
10
4607
13430527
Copy after login

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!

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