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