echo bindec('1101'); // Output 13
echo "<br>";
echo bindec('0101'); // Output 5
echo "<br>";
echo bindec('10110'); // Output is 22
echo "<br>";
echo bindec('101101101'); // Output is 365
echo "<br>";
echo bindec('111011100'); // Output is 476
echo "<br>";
Syntax
number bindec(string $binary);
Parameter | DESCRIPTION |
---|---|
$binary | Required : Binary number as Input string representing number to convert to equivalent decimal number. |
$binary = "000101";
echo bindec($binary); // Output: 5
$binary = "110010101011011010";
echo bindec($binary); // Output: 207610
$binary = "1011";
if (ctype_digit($binary)) {
echo bindec($binary); // Output: 11
}
$binary = "1010 0011"; // Spaces between bits
$binary_clean = str_replace(' ', '', $binary); // Remove spaces
echo bindec($binary_clean); // Output: 163
$binary = "1001011";
$decimal = bindec($binary);
echo "Binary: $binary to Decimal: $decimal"; // Output: Binary: 1001011 to Decimal: 75
$binary = "101.101";
list($intPart, $fracPart) = explode('.', $binary);
$decimal = bindec($intPart) + bindec($fracPart) / pow(2, strlen($fracPart));
echo $decimal; // Output: 5.625
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.