pack H* C# conversion

Wednesday, June 02, 2010 9:39:00 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;
}

 

Share This Using Popular Bookmarking Services
You must sign in to this site to post comments.
Site Map | Printable View | © 2008 - 2012 NuRoN Consulting, INC | Powered by mojoPortal | HTML 5 | CSS | Original design by Andreas Viklund
Share This Using Popular Bookmarking Services