MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / method

Function method

String_containing_binary.py:53–65  ·  view source on GitHub ↗
(S)

Source from the content-addressed store, hash-verified

51""" 3rd Approach """
52
53def method(S):
54 V = int(S,2)
55 print('Decimal form of {} is {}\n'.format(S, V))
56 operationCount = 0
57 while V != 0:
58 if V % 2 == 0:
59 print('V = {}\t->\t even divide by 2, Now V = {}'.format(int(V), int(V / 2)))
60 V /= 2
61 else:
62 print('V = {}\t->\t odd subtract 1, Now V = {}'.format(int(V), int(V-1)))
63 V -= 1
64 operationCount += 1
65 print('\nNumber of operations =', operationCount)
66
67
68method('011100')

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected