PHP base_convert function



 The function of PHP base_convert function can convert numbers between arbitrary bases. For example, we can convert a string of hexadecimal system to binary system of digital representation. Through three simple parameter settings, The PHP base_convert function performs conversion. The " ASCII Code Table " provided by this site has commonly used ASCII representations of binary, decimal, and hexadecimal systems. Welcome to use more. The following continues to introduce the syntax and examples of the PHP base_convert function.


PHP base_convert function syntax rules
base_convert (string $number, int $frombase, int $tobase)
The PHP base_convert function has a total of three parameters that can be used, and all three parameters are required.
  • string $number: The string to be converted .
  • int $frombase: Set the carry system of string $number.
  • int $tobase: Set the carry system to be converted.
With these three parameters, the base_convert function can convert the $number from the $frombase carry system to the $tobase carry system.

PHP base_convert function example
<?php
  $mynumber_1 = '17';
  echo base_convert($mynumber_1, 16, 2);
  echo'<br>';
  $mynumber_2 = '00010111';
  echo base_convert($mynumber_2, 2, 16);
?>
Example output
10111
17
The example prepares two different base_convert function conversion effects. The first group is to convert the number 17 from hexadecimal to binary and output it through echo . The second group is to reverse the base_convert function to convert the number 00010111 from 2. The carry system is converted to the hexadecimal system, so the result is converted to the number 17. This example is the effect of the base_convert function converting between two different carry systems. The same result can also be found in the " ASCII Code Table ".

The "echo'<br>';" in the example is only used to output line breaks. For detailed usage, please refer to: PHP echo line break .

Post a Comment

0 Comments