title: Why bin_to_dec() returns 0?
body: <p>Can anybody tell me why it returns 0?
  I have <strong>Input:</strong></p>
  <blockquote>
  <p>5 2</p>
  <p>1 0 1 1 0</p>
  </blockquote>
  <p>And 2 queries <strong>1 X</strong> to flip Xth bit in array:</p>
  <blockquote>
  <p>1 2 (result {1 1 1 1 0} )</p>
  </blockquote>
  <p><strong>0 L R</strong> to take a subarray and convert it into Decimal:</p>
  <blockquote>
  <p>0 1 4 (Here it takes {1,1,1,1})</p>
  </blockquote>
  <p>In this case it should print 15.
  But this printing just zero?</p>
  <p><strong>My code:</strong></p>
  <pre><code>
  #include &lt;iostream&gt;
  using namespace std;
  
  
  const int maxn = 1e6 +500;
  char a[maxn];
  //That's function which I'm stuck with
  long bin_to_dec(char *s)
  {
      short i;
      long res = 0;
      
      for (i = 0;i&lt;sizeof(long)*8 &amp;&amp; s[i];++i)
      {
          res&lt;&lt;=1;
          res |=(s[i]-'0');
          
      }
  
      
      return res;
  }
  //This function responsible for queries
  //Arguments which it takes : vid - type of query,int inx - first parameter,inx1 - 2nd parameter
  int zapros(int vid,int inx,int inx1 = 0)
  {
      string s = &quot;&quot;;
      if (vid == 1)
      {
          a[inx] +=1;
          
      }
      else
      {
          int c = 1;
          char ch[inx1+1];
          for (int k = inx;k&lt;=inx1;k++)
          {
              
              ch[c] = a[k];
              c++;
              
          }
      
          cout&lt;&lt;bin_to_dec(ch);
          /*
          for (int k = inx;k&lt;=inx1;k++)
          {
              s+=a[k];
          }*/
          
      }
  }
  
  
  
  int main()
  {
      int n,q;
      int vid,inx,inx1;
      cin&gt;&gt;n&gt;&gt;q;
      for (int i =1;i&lt;=n;i++)
      {
          cin&gt;&gt;a[i];
      }
      for (int j =1;j&lt;=q;j++)
      {
          cin&gt;&gt;vid;
          if (vid == 1)
          {
              cin&gt;&gt;inx;
              zapros(vid,inx);
          }
          else
          {
              cin&gt;&gt;inx&gt;&gt;inx1;
              zapros(vid,inx,inx1);
          }
      }
      
      
      
      return 0;
  }
  </code></pre>
  <p><em>I'm  a beginner in C++,so please dont'be strict;)</em></p>