Task 1:
You are given a string S of length N which encodes a non-negative number V in a binary form. Two types of operations may be performed on it to modify its value:
if V is odd, subtract 1 from it;
if V is even, divide it by 2;
These operations are performed until the value of V becomes 0.
Example 1: S = "011100", its value V initially is 28. The value of V would changes as follows:
V = 28
V = 14
V = 7
V = 6
V = 3
V = 2
V = 1
the function should return 7.
Example 2:
S = "111", should return 5.