Mega Code Archive

 
Categories / C# / Data Types
 

Hex String To Bytes (2)

/*  * Copyright (c) United Binary LLC.  All rights reserved.  *   * This code is licensed under the MIT License  *   * SEE: http://harnessit.codeplex.com/license  *   */ #region using ... using System; using System.Text; #endregion namespace UnitedBinary.Core.Utility.Text {   /// <include file='Text.xml' path='/Docs/Format/Class/*'/>   public sealed class Format   {     private Format() {}     /// <include file='Text.xml' path='/Docs/Format/HexStringToBytes/*'/>     public static byte[] HexStringToBytes(string source)     {       if (source.Length % 2 != 0)       {         throw new ArgumentException("Argument must be divisible by two.", "source");       }       byte[] bytes = new byte[source.Length/2];       for (int i=0; i < bytes.Length; i++)       {         bytes[i] = Convert.ToByte(source.Substring(i * 2, 2), 16);       }       return bytes;     }   } }