title: C program to convert hexadecimal to integer
body: <p>It fails when it takes more than two digits....  </p>
  
  <p>Eg. Input: <code>0xf</code>  Output: <code>15</code><br>
  But Input:<code>0xFF</code>Output:<code>-1</code></p>
  
  <pre><code>char s[20],hexdigit=0,i=0,deci=0;
  scanf("%[^\n]",s);
  if(s[0]=='0' &amp;&amp; (s[1]== 'X' || s[1]=='x'))
      i=2;
  for(;s[i]!='\0';i++){
  
      if(s[i]&gt;='0' &amp;&amp; s[i]&lt;='9')
          hexdigit=s[i]-'0';
      else if(s[i]&gt;='a' &amp;&amp; s[i]&lt;='f')
          hexdigit=s[i]-'a'+10;
      else if(s[i]&gt;='A' &amp;&amp; s[i]&lt;='F')
          hexdigit=s[i]-'A'+10;
      else
          break;
      deci=(16*deci)+hexdigit;
  }
      printf("\n%d",deci);  
  </code></pre>