PHP bindec

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $val1= '110011';  

  2. $val2='110';  

  3. $val3='11100111';  

  4. $zdec1=bindec($val1);  

  5. $zdec2=bindec($val2);  

  6. $zdec3=bindec($val3);  

  7. echo "Decimal value of $val1 is $zdec1
    ";  

  8. echo "Decimal value of $val2 is $zdec2
    ";  

  9. echo "Decimal value of $val3 is $zdec3
    ";  

  10. ?>  

Output :

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