title: Combine four 8-bit unsigned ints into one 32-bit unsigned int
body: <p>Given an array of four 8-bit unsigned ints, for example a <a href="http://en.wikipedia.org/wiki/RGBA_color_space" rel="nofollow noreferrer">32-bit RGBA color</a></p>
  
  <pre><code>rgba = [255, 255, 255, 255] # white
  </code></pre>
  
  <p>what is the most efficient way to combine these four <a href="http://ruby-doc.org/core-2.1.5/Fixnum.html" rel="nofollow noreferrer">Fixnums</a> into a single 32-bit <a href="http://ruby-doc.org/core-2.1.5/Integer.html" rel="nofollow noreferrer">Integer</a>?</p>
  
  <p>Currently, I'm using pack and unpack:</p>
  
  <pre><code>rgba.pack('C*').unpack('L')[0] #=&gt; 4294967295
  
  # Check work: same value as corresponding hex literal
  0xffffffff #=&gt; 4294967295
  </code></pre>
  
  <p>but I wonder if there's a more efficient way.  I found this C++ question:</p>
  
  <p><a href="https://stackoverflow.com/questions/1294649/cleanest-way-to-combine-two-shorts-to-an-int">Cleanest way to combine two shorts to an int</a></p>
  
  <p>and I think <code>&lt;&lt;</code> is a "shift" and <code>|</code> is a "mask", but I don't know enough about those operators, and have never used them in ruby.</p>