title: Fastest way to convert int to 4 bytes in C#
body: <p>What is a fastest way to convert int to 4 bytes in C# ?</p>
  
  <p>Fastest as in execution time not development time.</p>
  
  <p>My own solution is this code:</p>
  
  <pre><code>byte[] bytes = new byte[4];
  unchecked
  {
   bytes[0] = (byte)(data &gt;&gt; 24);
   bytes[1] = (byte)(data &gt;&gt; 16);
   bytes[2] = (byte)(data &gt;&gt; 8);
   bytes[3] = (byte)(data);
  }
  </code></pre>
  
  <p>Right now I see that my solution outperforms both <code>struct</code> and <code>BitConverter</code> by couple of ticks.</p>
  
  <p>I think the unsafe is probably the fastest option and accept that as an answer but I would prefer to use a managed option.</p>