title: Improve performance of string to binary number conversion
body: <p>This is one of the questions that I faced in competitive programming.</p>
  
  <p>Ques) You have an input String which is in binary format <code>11100</code> and you need to count number of steps in which number will be zero. If number is <code>odd -&gt; subtract it by 1</code>, if <code>even -&gt; divide it by 2</code>.</p>
  
  <p>For example </p>
  
  <p>28 -> 28/2</p>
  
  <p>14 -> 14/2</p>
  
  <p>7 -> 7-1</p>
  
  <p>6 -> 6/2</p>
  
  <p>3 -> 3-1</p>
  
  <p>2 -> 2/2</p>
  
  <p>1-> 1-1</p>
  
  <p>0 -> STOP</p>
  
  <p>Number of steps =7</p>
  
  <p>I came up with the following solutions </p>
  
  <pre><code>public int solution(String S) {
      // write your code in Java SE 8
      String parsableString = cleanString(S);
      int integer = Integer.parseInt(S, 2);
      return stepCounter(integer);
  }
  
  private static String cleanString(String S){
      int i = 0;
      while (i &lt; S.length() &amp;&amp; S.charAt(i) == '0')
          i++;
      StringBuffer sb = new StringBuffer(S);
      sb.replace(0,i,"");
      return sb.toString();
  }
  
  private static int stepCounter(int integer) {
      int counter = 0;
      while (integer &gt; 0) {
          if (integer == 0)
              break;
          else {
              counter++;
              if (integer % 2 == 0)
                  integer = integer / 2;
              else
                  integer--;
          }
      }
      return counter;
  }
  </code></pre>
  
  <p>The solution to this question looks quite simple and straightforward, however the performance evaluation of this code got me a big ZERO. My initial impressions were that converting the string to int was a bottleneck but failed to find a better solution for this. Can anybody please point out to me the bottlenecks of this code and where it can be significantly improved ?</p>