PHP base_convert( ) Math Function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The base_convert() function in PHP is used to convert a number given in an arbitrary base to a desired base. Both the base should be between 2 and 32 and bases with digits greater than 10 are represented with letters a-z i.e 10 is represented as a, 11 is represented as b and 35 is represented as z. The case of the letters is not sensitive. Syntax: string base_convert($inpNumber, $fromBase, $desBase) Parameters Used: This function accepts three parameters and are described below: $inpNumber : It is the number to be converted.$fromBase : It is the original base of the number.$desBase : It is the base to which you want to convert. Return Value: It returns a string that represents the number converted to the desired base. Examples: Input : base_convert(B296, 16, 8) Output : 131226 Input : base_convert(B296, 16, 2) Output : 1011001010010110 Input : base_convert(621, 8, 16) Output : 191 Input : base_convert(110011, 2, 16) Output : 33 Below programs illustrate the base_convert() function in PHP: Converting hexadecimal to octal: PHP <?php $hexadec = "B296"; echo base_convert($hexadec, 16, 8); ?> Output: 131226 Converting hexadecimal to binary: PHP <?php $hexadec = "B296"; echo base_convert($hexadec, 16, 2); ?> Output: 1011001010010110 Converting octal to hexadecimal: PHP <?php $octal = "621"; echo base_convert($octal, 8, 16); ?> Output: 191 Converting binary to hexadecimal: PHP <?php $binary = "110011"; echo base_convert($binary, 2, 16); ?> Output: 33 Reference: http://php.net/manual/en/function.base-convert.php Comment More infoAdvertise with us Next Article PHP base_convert( ) Math Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-math PHP-function +1 More Practice Tags : Misc Similar Reads PHP mb_convert_kana() Function The mb_convert_kana() is an inbuilt function in PHP that is used to convert text into full-width and half-width. Syntax:mb_convert_kana($string, $mode, $encoding) : stringParameters: This function accepts three parameters that are described below. $string: This is the string that we want to convert 2 min read PHP Math Functions PHP is a scripting language that comes with many built-in math functions and constants. These tools help you do basic math, solve more complex problems, and work with different math concepts. This guide gives an overview of PHP's math functions and constants, along with examples, practical uses, and 5 min read PHP mb_convert_variables() Function The mb_convert_variables() is an inbuilt function in PHP that transforms the character code into variables. Syntax: mb_convert_variables( $to_encoding, $from_encoding, $var, ...$vars ): string|falseParameters: This function accepts four parameters that are described below: $to_encoding: The characte 1 min read PHP decoct( ) Function In the earlier days of computing, octal numbers and the octal numbering system was very popular for counting inputs and outputs because as it works in counts of eight, inputs and outputs were in counts of eight, a byte at a time. Due to a wide usage of octal number system many times it happens that 2 min read PHP | bcsqrt() Function The bcsqrt() function in PHP is an inbuilt function and is used to evaluate the square root of an arbitrary precision number. This function accepts an arbitrary precision number as a string and returns the square root of the number after scaling the result to a specified precision. Syntax: string bc 2 min read PHP asin( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. One of such function is asin() function. The asin() function in PHP is used to find the arc sine of a number in radians. We already 2 min read PHP acos( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. One of such function is acos() function. The acos() function in PHP is used to find the arc cosine of a number in radians. We alrea 2 min read PHP | gmp_com() Function The gmp_com() is an inbuilt function in PHP which is used to calculate the one's complement of a GMP number(GNU Multiple Precision : For large numbers). Syntax: gmp_com($num) Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax. This parameter can 2 min read PHP | bcscale() Function The bcscale() function is an inbuilt function in PHP. It sets the default scale parameters for all bc math function calls. When we call the function bcscale() in a program, the parameter passed in this function thus becomes the default scale factor which by default is zero. Syntax: int bcscale($scal 2 min read PHP | bcdiv() Function The bcdiv() function in PHP is an inbuilt function and is used to divide two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the division of the two numbers after scaling the result to a specified precision. Syntax: string bcdiv ( $num_str1, 2 min read Like