← All Exercises

Binary to Decimal Converter

basicjavascript~10min

Background

Binary-to-decimal conversion is essential in low-level programming, networking, and understanding number systems.

Problem

Write a function that takes a string of 0s and 1s representing a binary number and returns its decimal equivalent.

Input

A string containing only the characters 0 and 1.

Output

A non-negative integer representing the decimal value.

Sample tests

Sample 1

Input: "1010"
Expected: 10

Your solution

Learning objective

Understand binary number representation and bit-level conversion logic.