题目描述
Given an string of binary number n. The task is to convert binary fractional n into its 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)
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
输入格式
见题面
输出格式
见题面
样例输入
n = 110.101
样例输出
6.625