This function provide the functionality of base conversion.
PHP base_convert() Function Example:
This function provide the functionality of base conversion. Using this method, we are convert the number base from one base to another base.
Syntax:
base_convert(number, frombase, tobase)
The number parameter is original value that convert from base to to base.
Example:
<?php $decimal = "935648124576358"; $hexa_decimal = base_convert($decimal, 10, 16); echo "$decimal decimal = $hexa_decimal hexadecimal.<br/>"; $oct = "01234567"; $hexa_decimal = base_convert($oct, 8, 16); echo "$oct octal = $hexa_decimal hexadecimal.<br/>"; $oct = "01234567"; $decimal = base_convert($oct, 8, 10); echo "$oct octal = $decimal decimal.<br/>"; $decimal = "342391"; $oct = base_convert($decimal, 10, 8); echo "$decimal decimal = $oct octal.<br/>"; $oct = "342391"; $binary = base_convert($oct, 8, 2); echo "$oct octal = $binary binary."; ?>
In this example you can see the different types of convesion using base_convert() function.
Output:
The output of this example is:
935648124576358 decimal = 352f78e19a266 hexadecimal. 01234567 octal = 53977 hexadecimal. 01234567 octal = 342391 decimal. 342391 decimal = 1234567 octal. 342391 octal = 11100010011001 binary.
[ 0 ] Comments