pack H* C# conversion
Posted by Ron Rechtman
Wednesday, June 02, 2010 9:39:10 AM
So I had to do manipulate data to a PHP app that needed to be pack("H*",...) in the PHP world. After a lot of digging I found
public static byte[] PackH(string hex)
{
if ((hex.Length % 2) == 1) hex += '0';
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}