title: Maximum of 63 bits in PHP?
body: <p>I'm building a system where I need to assign users access to a specific (individual) number of assets. These assets (potentially numbering  in the tens of thousands).</p>
  
  <p>I thought to do it with bitwise comparisons, so something like storing the value of 3 if a user has access to assets 1 and 2, a value of 7 for access to 1, 2 and 3, etc. etc.</p>
  
  <p>The access is not necessarily sequential, so a user could easily have access to assets 10, 12 and 24324.</p>
  
  <p>I quickly ran into a problem using bits where the server wouldn't pick up assets beyond the 63rd bit, so obviously I've either misunderstood something, or bits is a dumb way to store this kind of info.</p>
  
  <p>My code, running on a 64-bit Linux system, is this (just for testing purposes obviously, to discover just such limitations as this):</p>
  
  <pre><code>&lt;?php
  
  $bitwise = $_GET['bitwise'];
  
  if (isset($bitwise)) {
  
      echo "&lt;br/&gt;bitwise input: ";
      echo $bitwise;
      $bitcount = 0;
      for ($i=1;$i&lt;=$bitwise;$i*=2) {
  
          if (($i &amp; $bitwise) &gt; 0) {
  
              $bitcount++;
              echo "&lt;br/&gt;{$bitcount}: " . $i . " is in " . $bitwise;
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>?></p>
  
  <p>And I input test values via the querystring. However, no matter what value I input, the maximum count I can get to is 63.</p>
  
  <p>So, my question is: Is this simply because I'm using bitwise comparisons for something they're not ideal for (my theory), or is my implementation of it just wrong?</p>
  
  <p>My next go-to solution would be to store the "bits" in arrays, so if someone has access to assets 1, 2 and 3 I'll store their list as [1,2,3]. It's unlikely that someone has access to more than, say, a hundred specific assets. Is this a reasonable way to do it? I realize this puts the question somewhat into discussion-worthy territory, but hopefully it's still specific enough.</p>
  
  <p>Paramount concerns are, of course, performance if the server has to serve a large number of clients at the same time.</p>
  
  <p>(please excuse wrong terminology where applicable, hopefully my meaning is clear).</p>