title: Check if a string is a base 16 number
body: <p>I've been trying to solve this task, but I had no positive results.</p>
  
  <p>So, my task is to check if a string is a base 16 number.</p>
  
  <p>example  : s="1AB",  it will show YES 427</p>
  
  <p>Here is my code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  using namespace std;
   int power (int a, int b)
   {
       if(b==1) return a; 
       else return a*power(a,b-1);
   }
   void conv(char s[],int &amp;n)
   {
       int S=0,i,p=0;
       for(i=n-1;i&gt;=0;i--)
       {
           if(s[i]&gt;='0' &amp;&amp; s[i]&lt;='9')
              S+=(s[i]-48) * power(16,p); //ex:s[i]='1' ==&gt; S+=(49-49)*...
           else S+=(s[i]-55) * power(16,p); //s[i]='A' ==&gt; S+=(65-55) *...
           p++;
       }
   }
  int main()
  {
   int n,i,k=0;
   char s[255];
   cin.get(s,255);
   cin.get();
   n=strlen(s);
   for(i=0;i&lt;n;i++)
   {
       if(strchr("0123456789ABCDEF",s[i])) k++;
   }
   if(k==0) cout&lt;&lt;"not in base 16";
   else{
      conv(s,n); cout&lt;&lt;s;}
  return 0;
  }
  </code></pre>