w3resource

PHP: bindec function

Description

The bindec() function is used to convert a binary number to a decimal number.

Version:

(PHP 4 and above)

Syntax:

bindec(string_num)

Parameter:

Name Description Required /
Optional
Type
string_num The binary string to convert. Required String

Return value:

The decimal value of string_num

Value Type: Integer / Float.

Pictorial Presentation:

php-math_bindec

Example:

<?php
$val1= '110011';
$val2='110';
$val3='11100111';
$zdec1=bindec($val1);
$zdec2=bindec($val2);
$zdec3=bindec($val3);
echo "Decimal value of $val1 is $zdec1<br />";
echo "Decimal value of $val2 is $zdec2<br />";
echo "Decimal value of $val3 is $zdec3<br />";
?>

Output:

Decimal value of 110011 is 51
Decimal value of 110 is 6
Decimal   value of 11100111 is 231

View the example in the browser

See also

PHP Function Reference

Previous: base_convert
Next: ceil



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/bindec.php