(S)
| 51 | """ 3rd Approach """ |
| 52 | |
| 53 | def 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 | |
| 68 | method('011100') |
no outgoing calls
no test coverage detected