How to convert binary to floating point number in php

青灯夜游
Release: 2023-03-16 07:06:02
Original
3046 people have browsed it

Method: 1. Use bindec() to convert binary to decimal number, syntax "bindec (binary value)"; 2. Use type conversion function floatval() or settype() to convert decimal number to floating point Type, syntax "floatval(number)" or "settype(number, "float")".

How to convert binary to floating point number in php

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

php will convert binary Method for floating-point number

In PHP, if you want to convert binary to floating-point number, you need to convert binary to decimal number first.

Implementation method:

1. Use the bindec() function to convert binary numbers into decimal numbers

bindec($binary_string) Function converts the binary number $binary_string to a decimal number.

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str="11000110011";
$num=bindec($str);
echo "11000110011转为的十进制数是:".$num;
?>
Copy after login

How to convert binary to floating point number in php

2. Use the type conversion function floatval() or settype() to convert the decimal number to a floating point type.

  • floatval() function

The floatval() function is a function that specifically converts other types to floating point types. You can get the floating point value of a variable.

echo "<br>十进制数的数据类型为:";
var_dump($num);
$float= floatval($num);
echo "修改后的类型:";
var_dump($float);
Copy after login

How to convert binary to floating point number in php

  • settype() function

echo "<br>原数据类型为:";
var_dump($num);
settype($num, "float");
echo "修改后的类型:";
var_dump($num);
Copy after login

How to convert binary to floating point number in php

Recommended learning : "PHP Video Tutorial"

The above is the detailed content of How to convert binary to floating point number in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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