title: Concat 4 integers into one integer
body: <p>Hi i am trying to concatinate 4 integers one integer. I used the concatinate function found here : </p>
  
  <p><a href="https://stackoverflow.com/a/12700533/2016977">https://stackoverflow.com/a/12700533/2016977</a></p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>unsigned concatenate(unsigned x, unsigned y) {
      unsigned pow = 10;
      while(y &gt;= pow)
          pow *= 10;
      return x * pow + y;        
  }
  
  void stringtoint(){
      struct router *ptr;
      ptr=start;
  
      while(ptr!=NULL){
          int a;
          int b;
          int c;
          int d;
  
          sscanf(ptr-&gt;ip, "%d.%d.%d.%d", &amp;a, &amp;b, &amp;c, &amp;d);
          int num1 = concatenate(a,b);
          int num2 = concatenate(c,d);
          int num3 = concatenate(num1,num2);
          printf("%d\n",num3);
          ptr=ptr-&gt;next;
      };
  
  }
  </code></pre>
  
  <p><strong>The problem:</strong></p>
  
  <p>I am dealing with IP address numbers e.g. <code>198.32.141.140</code> i am breaking them down to 4 integers and concatenate them to form  <code>19832141140</code>, however my concatenate function is doing maths on the larger number like <code>198.32.141.140</code> (becomes) - ><code>-1642695340</code>
     but it is concatenating the IP which are small numbers e.g. <code>164.78.104.1</code> becomes <code>164781041</code> (which is correct)</p>
  
  <p>How should i solve the problem, basically i am trying to make a string of IP e.g. <code>198.32.141.140</code> into an <strong>integer</strong> number <code>19832141140</code> </p>