Count number of set bit in a binary string

Given a binary string of length n, and we are given a sequence of operations 1 or 2.

  1. print the number of ones in the string.
  2. decrement the number by 1 (formed by converting the binary string to decimal).

We have to print the number of ones whenever we are encountering 1.

Example
binary_string = “10000”
Operation Seq: “1212221”

1 -> print -> (1)
2 -> reduce to 15
1 -> print -> (4)
2 -> reduce to 14
2 -> reduce to 13
2 -> reduce to 12
1 -> print -> (2)
Answer: [1, 4, 2]

NB:
The problem was I couldn’t convert the string to decimal as the length of the string was 10^5. I wanted to understand how to solve this.