Home  >  Article  >  Backend Development  >  How to convert hexadecimal to floating point number in php

How to convert hexadecimal to floating point number in php

青灯夜游
青灯夜游Original
2022-04-24 20:49:453144browse

How to convert hexadecimal to floating point number in php: 1. Use the "hexdec (hexadecimal value)" or "base_convert (hexadecimal value, 16,10)" statement to convert hexadecimal to floating point number. Convert the system value to a decimal number; 2. Use the "floatval (decimal number)" statement to obtain the floating point value and convert the decimal number to a floating point number type.

How to convert hexadecimal to floating point number in php

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

php will enter 16 Method to convert system to floating point number

Implementation idea:

  • Convert hexadecimal value to decimal number---Function:hexdec(hexdecimal value)orbase_convert(hexdecimal value,16,10)function

    hexdec() function is specially used for hexadecimal values Convert to decimal number, and the bindec() function can convert numbers between any bases

  • Convert decimal number to floating point number--Function floatval()

    The floatval function is used to get the floating point value of a variable.

Implementation example:

<?php
$hex = "cceeff";
$num1=hexdec($hex);
$num2=base_convert($hex, 16, 10);

$float1=floatval($num1);
$float2=floatval($num2);
var_dump($float1);
var_dump($float2);
?>

How to convert hexadecimal to floating point number in php

Recommended learning: "PHP Video Tutorial"

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