Binary fraction to decimal
Basic Accuracy: 0.0% Submissions: 0 Points: 1

Given an string of binary number n. The task is to convert binary fractional n into it’s decimal equivalent.

 

Example 1:

Input:
n = 110.101
Output:
6.625
Explanation:
The given binary String is equivalent
to (6.625)10

Example 2:

Input:
n = 101.1101
Output:
5.8125
Explanation:
The given binary String is equivalent
to (5.8125)10

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function convertToDecimal() which takes an String n as input and returns the answer.

 

Expected Time Complexity: O(|n|)
Expected Auxiliary Space: O(1)

 

Constraints:
1 <= |n| <= 50

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.