An Example of base_convert of Binary Digital Conversion Function in php

  • 2021-08-03 09:49:44
  • OfStack

In this paper, an example is given to describe the realization method of binary digital conversion of base_convert () function in php. Share it for your reference. The details are as follows:

Syntax: base_convert (number, frombase, tobase)

参数 描述
number 必需,原始值.
frombase 必需,数字原来的进制.
tobase 必需,要转换的进制.

The PHP example code is as follows:

$hexadecimal='a37334'; 
echo base_convert($hexadecimal,16,2);   // Convert to 2 Binary output 101000110111001100110100
echo "<br>";
$number="123";
echo base_convert($number,10,2);    // Convert to 2 Binary output 1111011
echo "<br>";
echo base_convert($number,10,8);    // Convert to 8 Binary output 173
echo "<br>";
echo base_convert($number,10,16);    // Convert to 106 Binary output 7b
$number2="100000101";
echo "<br>";
echo base_convert($number2,2,10);    // Convert to 10 Binary output 261
echo "<br>";
echo base_convert($number2,2,8);    // Convert to 8 Binary output 405

Description: Returns a string containing the representation of number in tobase. The binary of number itself is specified by frombase, frombase and tobase can only be between 2 and 36 (including 2 and 36), and digits higher than decimal are represented by letters a-z, such as a for 10, b for 11 and z for 35.

I hope this article is helpful to everyone's PHP programming.


Related articles: