To convert a binary number to decimal in PHP, you can use the built-in bindec
function. This function takes a binary string as its argument and returns the equivalent decimal value.
Here's an example:
main.php115 chars5 lines
In this example, we convert the binary number "1010" to decimal by calling the bindec
function on it. The resulting decimal value is stored in the $decimal
variable and then outputted to the screen.
Note that bindec
only works with binary numbers. To convert numbers from other bases, you'll need to use a different function or algorithm.
gistlibby LogSnag