This article mainly introduces the base_convert () numeric conversion function in php, and demonstrates the conversion method between the decimal number and the binary number, the octal value and the hexadecimal value in the form of an example, it has good reference value. if you need it, you can refer to the following example to describe how to implement the base_convert () function in php. Share it with you for your reference. The details are as follows:
Syntax: base_convert (number, frombase, tobase)
Parameters |
Description |
Number |
Required, original value. |
Frombase |
Required. number in the original hexadecimal format. |
Tobase |
Required. the hexadecimal format to be converted. |
The PHP instance code is as follows:
The code is as follows:
$ Hexadecimal = 'a37334 ';
Echo base_convert ($ hexadecimal, 16,2); // Convert to binary output 101000110111001100110100
Echo"
";
$ Number = "123 ";
Echo base_convert ($ number, 1111011); // Convert to binary output
Echo"
";
Echo base_convert ($ number, 10, 8); // Convert to octal output 173
Echo"
";
Echo base_convert ($ number, 10, 16); // Convert to hexadecimal output 7b
$ Number2 = "100000101 ";
Echo"
";
Echo base_convert ($ number2, 2, 10); // Convert to decimal output 261
Echo"
";
Echo base_convert ($ number2, 2, 8); // Convert to octal output 405
Description: return a string that contains the tobase representation of the number. The number system is specified by frombase. both frombase and tobase can only be between 2 and 36 (including 2 and 36). numbers higher than decimal digits are represented by a-z, for example, a indicates 10, B indicates 11, and z indicates 35.
I hope this article will help you with PHP programming.