Binary to Decimal Converter

Easy
22
88.0% Acceptance

In this lab, your task is to write a Python function named convert_binary that converts a binary string to its decimal equivalent. The key constraint is to achieve this without using any built-in methods for direct conversion.

Function Requirements

  • The function should be named convert_binary.
  • It must accept a binary string (e.g., 0b1010) as input.
  • The function should return the decimal equivalent of the binary string.

Examples

  1. Input: '0b101'
    Output: 5

  2. Input: '0b1111'
    Output: 15

  3. Input: '0b0'
    Output: 0

Notes

  • Ensure that your function can handle various lengths of binary strings.
  • Remember, the use of direct binary-to-decimal conversion functions provided by Python is not allowed. You need to implement the conversion logic manually.