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, has good reference value and needs
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, has good reference value and needs
This article describes how to convert the base _ convert () function into numbers in php. Share it with you for your reference. The details are as follows:
Syntax: base_convert (number, frombase, tobase)
Parameter description
Number is required, the original value.
Frombase required. numbers are in the original hexadecimal format.
Tobase is 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.
,