Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

bindec

Converts a binary string to a decimal number.

Syntax

bindec(string $binary_string): int|float

Parameters

ParameterTypeDescription
$binary_stringstringA string of zeros and ones.

Return value

int|floatThe decimal number.

Examples

Binary to decimal:

<?php
 
echo bindec('1010'), ' ', bindec('11111111');

Output:

10 255

Notes

Stray characters in the string trigger a deprecation notice — validate the input first.

See also

  • decbin — Converts a number to binary.
  • base_convert — Converts a number from one base to another.
  • hexdec — Converts a hexadecimal string to a decimal number.

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.