title: IP-addresses stored as int results in overflow?
body: <p>I'm writing a chat-server in node.js, and I want to store connected users IP-addresses in a mysql database as (unsigned) integers.
  I have written a javascript method to convert an ip-address as string to an integer. I get some strange results however.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>function ipToInt(ip) {
      var parts = ip.split(".");
      var res = 0;
  
      res += parseInt(parts[0], 10) &lt;&lt; 24;
      res += parseInt(parts[1], 10) &lt;&lt; 16;
      res += parseInt(parts[2], 10) &lt;&lt; 8;
      res += parseInt(parts[3], 10);
  
      return res;
  }
  </code></pre>
  
  <p>When I run call the method as <code>ipToInt("192.168.2.44");</code> the result I get is <code>-1062731220</code>.
  It seems like an overflow has occurred, which is strange, because the expected output <code>(3232236076)</code> is inside the number range in javascript (2^52).</p>
  
  <p>When I inspect <code>-1062731220</code> in binary form, I can see the <code>3232236076</code> is preserved, but filled with leading 1's.</p>
  
  <p>I'm not sure, but I think the problem is with signed vs. unsigned integers.</p>
  
  <p>Can any of you explain what is going on? 
  And possibly how to parse <code>-1062731220</code> back to an string ip?</p>