How to convert data to decimal in php

青灯夜游
Release: 2023-03-14 17:00:02
Original
2036 people have browsed it

Conversion method: 1. Use "bindec(value)" to convert binary to decimal; 2. Use "octdec(value)" to convert octal to decimal; 3. Use "hexdec(value) )", you can convert hexadecimal to decimal; 4. Use "base_convert(value, original base, 10);".

How to convert data to decimal in php

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

php converts data For decimal

1, use the bindec() function--binary number to decimal number

bindec() function converts a binary number to a decimal number.

<?php
echo bindec("0011") . "<br>";
echo bindec("01") . "<br>";
echo bindec("11000110011") . "<br>";
echo bindec("111");
?>
Copy after login

How to convert data to decimal in php

2. Use the octdec() function--octal number to decimal number

octdec() function to convert octal number is a decimal number.

<?php
echo octdec("36") . "<br>";
echo octdec("12") . "<br>";
echo octdec("3063") . "<br>";
echo octdec("106");
?>
Copy after login

How to convert data to decimal in php

3. Use the hexdec() function--hexadecimal number to decimal number

hexdec() function Convert hexadecimal number to decimal number.

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

How to convert data to decimal in php

4. Use the base_convert() function--convert between arbitrary bases

base_convert() function in any base Convert numbers between.

Syntax:

base_convert(number,frombase,tobase);
Copy after login
ParametersDescription
numberRequired. Specifies the number to be converted.
frombaseRequired. 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.
tobaseRequired. 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.

Example: Convert other bases to decimal

<?php
echo base_convert("cceeff",16,10) . "<br>";//16进制转10进制
echo base_convert("3063",8,10) . "<br>";//8进制转10进制
echo base_convert("11000110011",2,10);//2进制转10进制
?>
Copy after login

How to convert data to decimal in php

Recommended study: "PHP Video Tutorial

The above is the detailed content of How to convert data to decimal 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!