X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Binary number to decimal number
Basic Accuracy: 64.26% Submissions: 13090 Points: 1

Given a Binary Number B, find its decimal equivalent.
 

Example 1:

Input: B = 10001000
Output: 136

Example 2:

Input: B = 101100
Output: 44

 

Your Task:
You don't need to read or print anything. Your task is to complete the function binary_to_decimal() which takes the binary number as string input parameter and returns its decimal equivalent.

 

Expected Time Complexity: O(K * Log(K)) where K is number of bits in binary number.
Expected Space Complexity: O(1)

 

Constraints:
1 <= number of bits in binary number  <= 16

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Binary number to decimal number

Output Window