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)_{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

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def convertToDecimal(self, n):

        # code here 

Solutions:
class Solution:

	def convertToDecimal(self, n):
		l = n.split('.')
		d = len(l[0]) - 1
		c = 0
		for i in l[0]:
			if i == '1':
				c += 2 ** d
			d -= 1
		e = 0.5
		h = 0
		for i in l[1]:
			if i == '1':
				h += e
			e = e / 2
		h = str(h)
		h = h[1:]
		return str(c) + h


class Solution:

	def convertToDecimal(self, n):
		l = n.split('.')
		d = len(l[0]) - 1
		c = 0
		for i in l[0]:
			if i == '1':
				c += 2 ** d
			d -= 1
		e = 0.5
		h = 0
		for i in l[1]:
			if i == '1':
				h += e
			e = e / 2
		h = str(h)
		h = h[1:]
		return str(c) + h
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = input()
		ob = Solution()
		print(ob.convertToDecimal(n))