title: Creating a byte array in ruby (c# example code)
body: <p>I need to do something like this, in ruby:</p>
  
  <pre><code>    private byte[] ResourceHashToByteArray(string hex)
      {
          int NumberChars = hash.Length;
          byte[] bytes = new byte[NumberChars / 2];
          for (int i = 0; i &lt; NumberChars; i += 2) bytes[i / 2] = Convert.ToByte(hash.Substring(i, 2), 16);
          return bytes;
      }
  </code></pre>
  
  <p>What would be the optimum/most common/best practice way of doing this in Ruby?</p>
  
  <p>I have tried the following methods to no avail:</p>
  
  <pre><code>Digest::MD5.digest(hex)
  String.unpack(hex)
  String.bytes
  </code></pre>