title: PHP - unpack as unsigned int
body: <p>How do I convert a binary string to an unsigned int?</p>
  
  <p>I'm doing</p>
  
  <pre><code>$id = unpack('V', substr($dir, $mid * 12, 4))[1];
  echo $id . '&lt;br/&gt;';
  </code></pre>
  
  <p>Where <code>V</code>, according to documentation, is</p>
  
  <blockquote>
    <p>unsigned long (always 32 bit, little endian byte order)</p>
  </blockquote>
  
  <p>And it prints -992455690. How is this possible?</p>
  
  <p><strong>Update:</strong> found this in the documentation:</p>
  
  <blockquote>
    <p>Note that PHP internally stores integral values as signed. If you unpack a large unsigned long and it is of the same size as PHP internally stored values the result will be a negative number even though unsigned unpacking was specified.</p>
  </blockquote>
  
  <p>So now the question is, what's the point of the <code>V</code> format if its identical to the signed version, other than to create confusion?</p>