title: C++: Fastest way to merge and split a uint into 4 bytes
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/741212/fastest-method-to-split-a-32-bit-number-into-bytes-in-c">Fastest Method to Split a 32 Bit number into Bytes in C++</a>  </p>
  </blockquote>
  
  
  
  <p>Is there a way to merge/split a uint into 4 bytes quicker than what I'm currently doing? Maybe some inline assembler that has a native opcode that can do it in a single instruction?</p>
  
  <pre><code>// merge into x0
  unsigned int x0 = (data[i] &lt;&lt; 24) | (data[i+1] &lt;&lt; 16) | (data[i+2] &lt;&lt; 8) | data[i+3]; 
  
  
  // split x0
  outputBuffer[i] = (x0 &gt;&gt; 24);
  outputBuffer[i+1]  = (x0 &gt;&gt; 16) &amp; 0xFF;
  outputBuffer[i+2]  = (x0 &gt;&gt; 8) &amp; 0xFF;
  outputBuffer[i+3]  = (x0) &amp; 0xFF;
  </code></pre>